Documentation ¶
Index ¶
- Constants
- func ClientFromFile(ctx context.Context, filepath string, scopes []string, tok *oauth2.Token) (*http.Client, error)
- func ConfigFromBytes(configJSON []byte, scopes []string) (*oauth2.Config, error)
- func ConfigFromEnv(envVar string, scopes []string) (*oauth2.Config, error)
- func ConfigFromFile(file string, scopes []string) (*oauth2.Config, error)
- func HTTPGetBearerToken(url, token string) (*http.Response, error)
- func HTTPGetBearerTokenBody(url, token string) (*http.Response, []byte, error)
- func NewClientFileStore(credentials []byte, scopes []string, tokenPath string, useDefaultDir bool, ...) (*http.Client, error)
- func NewClientFileStoreWithDefaults(googleCredentials []byte, googleScopes []string, forceNewToken bool) (*http.Client, error)
- func NewClientFileStoreWithDefaultsCliEnv(googleCredentialsEnvVar, googleScopesEnvVar string) (*http.Client, error)
- func NewClientFromJWTJSON(ctx context.Context, svcAccountConfig []byte, scopes ...string) (*http.Client, error)
- func NewClientOAuthCLITokenStore(cfg ClientOAuthCLITokenStoreConfig) (*http.Client, error)
- func NewClientSvcAccountFromFile(ctx context.Context, svcAccountConfigFile string, scopes ...string) (*http.Client, error)
- type ClientOAuthCLITokenStoreConfig
- type ClientUtil
- func (apiutil *ClientUtil) GetPlusPerson() (GooglePlusPerson, error)
- func (apiutil *ClientUtil) GetSCIMUser() (scim.User, error)
- func (apiutil *ClientUtil) GetSCIMUserOld() (scim.User, error)
- func (apiutil *ClientUtil) GetUserinfo() (GoogleUserinfo, error)
- func (apiutil *ClientUtil) GetUserinfoEmail() (GoogleUserinfoEmail, error)
- func (apiutil *ClientUtil) SetClient(client *http.Client)
- type Credentials
- type CredentialsContainer
- type GoogleConfigFileStore
- type GooglePlusPerson
- type GooglePlusPersonImage
- type GooglePlusPersonName
- type GoogleUserinfo
- type GoogleUserinfoEmail
- type GoogleUserinfoOpenIDConnectV2
Constants ¶
const ( GoogleAPIUserinfoURL = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json" GoogleAPIPlusPeopleURL = "https://www.googleapis.com/plus/v1/people/me" GoogleAPIEmailURL = "https://www.googleapis.com/userinfo/email" // deprecated )
const ( ClientSecretEnv = "GOOGLE_APP_CLIENT_SECRET" // #nosec G101 EnvGoogleAppCredentials = "GOOGLE_APP_CREDENTIALS" // #nosec G101 EnvGoogleAppScopes = "GOOGLE_APP_SCOPES" ScopeDrive = slides.DriveScope // See, edit, create, and delete all of your Google Drive files ScopeDriveFile = slides.DriveFileScope // View and manage Google Drive files and folders that you have opened or created with this app ScopeDriveRead = slides.DriveReadonlyScope // See and download all your Google Drive files ScopePresentations = slides.PresentationsScope // View and manage your Google Slides presentations ScopePresentationsRead = slides.PresentationsReadonlyScope // View your Google Slides presentations ScopeSpreadsheets = slides.SpreadsheetsScope // See, edit, create, and delete your spreadsheets in Google Drive ScopeSpreadsheetsRead = slides.SpreadsheetsReadonlyScope // View your Google Spreadsheets ScopeUserEmail = "https://www.googleapis.com/auth/userinfo#email" ScopeUserProfile = "https://www.googleapis.com/auth/userinfo.profile" // call https://www.googleapis.com/oauth2/v1/userinfo?alt=json )
const (
GoogleAPIURLUserinfo = "https://openidconnect.googleapis.com/v1/userinfo"
)
Variables ¶
This section is empty.
Functions ¶
func ClientFromFile ¶
func ConfigFromBytes ¶
ConfigFromBytes returns an *oauth2.Config given a byte array containing the Google client_secret.json data.
func HTTPGetBearerToken ¶ added in v0.13.0
func HTTPGetBearerTokenBody ¶ added in v0.13.0
func NewClientFileStore ¶
func NewClientFileStore( credentials []byte, scopes []string, tokenPath string, useDefaultDir bool, forceNewToken bool, state string) (*http.Client, error)
NewClientFileStore returns a `*http.Client` with Google credentials in a token store file. It will use the token file credentials unless `forceNewToken` is set to true.
func NewClientFileStoreWithDefaults ¶
func NewClientFileStoreWithDefaults(googleCredentials []byte, googleScopes []string, forceNewToken bool) (*http.Client, error)
NewClientFileStoreWithDefaults returns a `*http.Client` using file system cache for access tokens.
func NewClientFileStoreWithDefaultsCliEnv ¶
func NewClientFileStoreWithDefaultsCliEnv(googleCredentialsEnvVar, googleScopesEnvVar string) (*http.Client, error)
NewClientFileStoreWithDefaultsCliEnv instantiates an `*http.Client` for the Google API for use from the command line interface (CLI). It will prompt the user to open the browser to auth when necessary.
func NewClientFromJWTJSON ¶
func NewClientOAuthCLITokenStore ¶ added in v0.20.0
func NewClientOAuthCLITokenStore(cfg ClientOAuthCLITokenStoreConfig) (*http.Client, error)
Types ¶
type ClientOAuthCLITokenStoreConfig ¶ added in v0.20.0
type ClientUtil ¶
type ClientUtil struct { Client *http.Client User GoogleUserinfo `json:"user,omitempty"` }
ClientUtil is a client library to retrieve the /userinfo endpoint which is not included in the Google API Go Client. For other endpoints, please consider using The Google API Go Client: https://github.com/google/google-api-go-client
func NewClientUtil ¶
func NewClientUtil(client *http.Client) ClientUtil
func (*ClientUtil) GetPlusPerson ¶
func (apiutil *ClientUtil) GetPlusPerson() (GooglePlusPerson, error)
GetPlusPerson retrieves the userinfo from the https://www.googleapis.com/oauth2/v1/userinfo?alt=json endpoint.
func (*ClientUtil) GetSCIMUser ¶
func (apiutil *ClientUtil) GetSCIMUser() (scim.User, error)
func (*ClientUtil) GetSCIMUserOld ¶
func (apiutil *ClientUtil) GetSCIMUserOld() (scim.User, error)
func (*ClientUtil) GetUserinfo ¶
func (apiutil *ClientUtil) GetUserinfo() (GoogleUserinfo, error)
GetUserinfo retrieves the userinfo from the https://www.googleapis.com/oauth2/v1/userinfo?alt=json endpoint. Requires scope `ScopeUserProfile` `https://www.googleapis.com/auth/userinfo.profile`
func (*ClientUtil) GetUserinfoEmail ¶
func (apiutil *ClientUtil) GetUserinfoEmail() (GoogleUserinfoEmail, error)
GetUserinfoEmail retrieves the user's email from the https://www.googleapis.com/userinfo/email endpoint.
func (*ClientUtil) SetClient ¶
func (apiutil *ClientUtil) SetClient(client *http.Client)
type Credentials ¶
type Credentials struct { Type string `json:"type,omitempty"` ClientEmail string `json:"client_email" structs:"client_email" mapstructure:"client_email"` ClientID string `json:"client_id" structs:"client_id" mapstructure:"client_id"` ClientSecret string `json:"client_secret,omitempty"` ProjectID string `json:"project_id" structs:"project_id" mapstructure:"project_id"` PrivateKey string `json:"private_key" structs:"private_key" mapstructure:"private_key"` PrivateKeyID string `json:"private_key_id" structs:"private_key_id" mapstructure:"private_key_id"` AuthURI string `json:"auth_uri,omitempty"` TokenURI string `json:"token_uri,omitempty"` AuthProviderX509CertURL string `json:"auth_provider_x509_cert_url,omitempty"` ClientX509CertURL string `json:"client_x509_cert_url,omitempty"` RedirectURIs []string `json:"redirect_uris,omitempty"` }
Credentials represents a full GCP Service Account Key file. A simplified version is available in https://github.com/hashicorp/go-gcp-common/blob/main/gcputil/credentials.go#L44-L51
func CredentialsFromFile ¶
func CredentialsFromFile(file string) (Credentials, error)
func ReadCredentialsFile ¶ added in v0.20.0
func ReadCredentialsFile(name string) (*Credentials, error)
type CredentialsContainer ¶
type CredentialsContainer struct { Web *Credentials `json:"web,omitempty"` Raw []byte `json:"-"` Scopes []string `json:"scopes,omitempty"` // optional for self-contained app credentials }
func CredentialsContainerFromBytes ¶
func CredentialsContainerFromBytes(bytes []byte) (CredentialsContainer, error)
func CredentialsContainerFromFile ¶
func CredentialsContainerFromFile(file string) (CredentialsContainer, error)
func (*CredentialsContainer) Credentials ¶
func (cc *CredentialsContainer) Credentials() *Credentials
func (*CredentialsContainer) OAuth2Config ¶
func (cc *CredentialsContainer) OAuth2Config(scopes ...string) (*oauth2.Config, error)
type GoogleConfigFileStore ¶
type GoogleConfigFileStore struct { CredentialsRaw []byte Credentials *Credentials OAuthConfig *oauth2.Config Scopes []string TokenPath string UseDefaultDir bool ForceNewToken bool State string }
func (*GoogleConfigFileStore) Client ¶
func (gc *GoogleConfigFileStore) Client() (*http.Client, error)
Client returns a `*http.Client`.
func (*GoogleConfigFileStore) LoadCredentialsBytes ¶
func (gc *GoogleConfigFileStore) LoadCredentialsBytes(bytes []byte) error
LoadCredentialsBytes set this after setting Scopes.
func (*GoogleConfigFileStore) SetDefaultFilepath ¶
func (gc *GoogleConfigFileStore) SetDefaultFilepath() error
SetDefaultFilepath creates a default filepath for the file system based token file.
type GooglePlusPerson ¶
type GooglePlusPerson struct { Kind string `json:"kind,omitempty"` Etag string `json:"etag,omitempty"` Gender string `json:"gender,omitempty"` ObjectType string `json:"objectType,omitempty"` ID string `json:"id,omitempty"` DisplayName string `json:"displayName,omitempty"` Name GooglePlusPersonName `json:"name,omitempty"` URL string `json:"url,omitempty"` Image GooglePlusPersonImage `json:"image,omitempty"` IsPlusUser bool `json:"isPlusUser,omitempty"` Language string `json:"language,omitempty"` Verified bool `json:"verified,omitempty"` }
type GooglePlusPersonImage ¶
type GooglePlusPersonName ¶
type GoogleUserinfo ¶
type GoogleUserinfo struct { FamilyName string `json:"family_name,omitempty"` Gender string `json:"gender,omitempty"` GivenName string `json:"given_name,omitempty"` ID string `json:"id,omitempty"` Link string `json:"link,omitempty"` Locale string `json:"locale,omitempty"` Name string `json:"name,omitempty"` PictureURL string `json:"picture,omitempty"` }
type GoogleUserinfoEmail ¶
type GoogleUserinfoEmail struct { Email string `json:"email,omitempty"` IsVerified bool `json:"isVerified,omitempty"` }
func ParseGoogleUserinfoEmail ¶
func ParseGoogleUserinfoEmail(query string) (GoogleUserinfoEmail, error)
type GoogleUserinfoOpenIDConnectV2 ¶ added in v0.13.0
type GoogleUserinfoOpenIDConnectV2 struct { Sub string `json:"sub,omitempty"` Name string `json:"name,omitempty"` GivenName string `json:"given_name,omitempty"` FamilyName string `json:"family_name,omitempty"` Picture string `json:"picture,omitempty"` Email string `json:"email,omitempty"` EmailVerfied bool `json:"email_verified,omitempty"` Locale string `json:"locale,omitempty"` }
func GetMeInfo ¶
func GetMeInfo(bearerToken string) (GoogleUserinfoOpenIDConnectV2, error)