// JWTClient requires OAuth 2.0 JWT credentials. // Required for the 2-legged JWT flow. func JWTClient(email string, key []byte) Option { return func(o *Options) error { pk, err := internal.ParseKey(key) if err != nil { return err } o.Email = email o.PrivateKey = pk return nil } }
// ServiceAccountJSONKey uses the provided Google Developers // JSON key file to authorize the user. See the "Credentials" page under // "APIs & Auth" for your project at https://console.developers.google.com // to download a JSON key file. func ServiceAccountJSONKey(filename string) oauth2.Option { return func(opts *oauth2.Options) error { b, err := ioutil.ReadFile(filename) if err != nil { return err } var key struct { Email string `json:"client_email"` PrivateKey string `json:"private_key"` } if err := json.Unmarshal(b, &key); err != nil { return err } pk, err := internal.ParseKey([]byte(key.PrivateKey)) if err != nil { return err } opts.Email = key.Email opts.PrivateKey = pk opts.AUD = uriGoogleToken return nil } }