google

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: MIT Imports: 15 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

	UserinfoEmailScope   = "https://www.googleapis.com/auth/userinfo#email"
	UserinfoProfileScope = "https://www.googleapis.com/auth/userinfo.profile"

	SpreadsheetsReadonly     = "https://www.googleapis.com/auth/spreadsheets.readonly"
	SpreadsheetsReadonlyDesc = "Allows read-only access to the user's sheets and their properties."
	Spreadsheets             = "https://www.googleapis.com/auth/spreadsheets"
	SpreadsheetsDesc         = "Allows read/write access to the user's sheets and their properties."

	DriveReadonly     = "https://www.googleapis.com/auth/drive.readonly"
	DriveReadonlyDesc = "Allows read-only access to the user's file metadata and file content."
	DriveFile         = "https://www.googleapis.com/auth/drive.file"
	DriveFileDesc     = "Per-file access to files created or opened by the app."
	Drive             = "https://www.googleapis.com/auth/drive"
	DriveDesc         = "Full, permissive scope to access all of a user's files. Request this scope only when it is strictly necessary."
)
View Source
const (
	GoogleApiUrlUserinfo = "https://openidconnect.googleapis.com/v1/userinfo"
)

Variables

View Source
var (
	ClientSecretEnv = "GOOGLE_APP_CLIENT_SECRET"
)

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 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
}

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.

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"`
	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"`
}

func NewCredentialsFromFile added in v0.3.0

func NewCredentialsFromFile(file string) (Credentials, error)

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