google

package
v0.18.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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

)
View Source
const (
	GoogleAPIURLUserinfo = "https://openidconnect.googleapis.com/v1/userinfo"
)

Variables

This section is empty.

Functions

func ClientFromFile

func ClientFromFile(ctx context.Context, filepath string, scopes []string, tok *oauth2.Token) (*http.Client, error)

func ConfigFromBytes

func ConfigFromBytes(configJSON []byte, scopes []string) (*oauth2.Config, error)

ConfigFromBytes returns an *oauth2.Config given a byte array containing the Google client_secret.json data.

func ConfigFromEnv

func ConfigFromEnv(envVar string, scopes []string) (*oauth2.Config, error)

func ConfigFromFile

func ConfigFromFile(file string, scopes []string) (*oauth2.Config, error)

func HTTPGetBearerToken

func HTTPGetBearerToken(url, token string) (*http.Response, error)

func HTTPGetBearerTokenBody

func HTTPGetBearerTokenBody(url, token string) (*http.Response, []byte, error)

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 NewClientFromJWTJSON(ctx context.Context, svcAccountConfig []byte, scopes ...string) (*http.Client, error)

func NewClientOauthCliTokenStore

func NewClientOauthCliTokenStore(cfg ClientOauthCliTokenStoreConfig) (*http.Client, error)

func NewClientSvcAccountFromFile

func NewClientSvcAccountFromFile(ctx context.Context, svcAccountConfigFile string, scopes ...string) (*http.Client, error)

Types

type ClientOauthCliTokenStoreConfig

type ClientOauthCliTokenStoreConfig struct {
	Context       context.Context
	AppConfig     []byte
	Scopes        []string
	TokenFile     string
	ForceNewToken bool
	State         string
}

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"`
	ProjectID               string   `json:"project_id,omitempty"`
	PrivateKeyID            string   `json:"private_key_id,omitempty"`
	PrivateKey              string   `json:"private_key,omitempty"`
	ClientEmail             string   `json:"client_email,omitempty"`
	ClientID                string   `json:"client_id,omitempty"`
	ClientSecret            string   `json:"client_secret,omitempty"`
	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"`
}

func CredentialsFromFile

func CredentialsFromFile(file 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 GooglePlusPersonImage struct {
	URL       string `json:"url,omitempty"`
	IsDefault bool   `json:"isDefault,omitempty"`
}

type GooglePlusPersonName

type GooglePlusPersonName struct {
	FamilyName string `json:"familyName,omitempty"`
	GivenName  string `json:"givenName,omitempty"`
}

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

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL