Documentation
¶
Index ¶
- func CheckResponse(body []byte)
- type AccessToken
- type ClientID
- func (c *ClientID) Gen()
- func (c *ClientID) GetID() string
- func (c *ClientID) GetScopes() string
- func (c *ClientID) GetSecret() string
- func (c *ClientID) InitToken()
- func (c *ClientID) Refresh()
- func (c *ClientID) SetID(input string)
- func (c *ClientID) SetScopes(input string)
- func (c *ClientID) SetSecret(input string)
- func (c *ClientID) SetToken(body []byte)
- type JWT
- type JWTClaim
- type RefreshToken
- func (r *RefreshToken) GetAccessCode() string
- func (r *RefreshToken) GetAuthURL() string
- func (r *RefreshToken) GetToken() string
- func (r *RefreshToken) GetTokenURL() string
- func (r *RefreshToken) HasToken() bool
- func (r *RefreshToken) SetAccessCode(input string)
- func (r *RefreshToken) SetAuthURL(c *ClientID)
- func (r *RefreshToken) SetToken(input string)
- func (r *RefreshToken) SetTokenURL()
- type ServiceAccount
- func (s *ServiceAccount) Auth()
- func (s *ServiceAccount) GetClientID() string
- func (s *ServiceAccount) GetEmail() string
- func (s *ServiceAccount) GetPrivateKey() string
- func (s *ServiceAccount) GetTokenURI() string
- func (s *ServiceAccount) Init(scope, sub string)
- func (s *ServiceAccount) SetToken(body []byte)
- type TokenError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶
func CheckResponse(body []byte)
CheckResponse function will look into the returned HTTP response to check whether it actually contains an error
Types ¶
type AccessToken ¶
type AccessToken struct { Token string `json:"access_token,omitempty"` Expiry int `json:"expires_in,omitempty"` RefreshToken string `json:"refresh_token,omitempty"` Scopes string `json:"scope,omitempty"` TokenType string `json:"token_type,omitempty"` }
AccessToken struct represents a JSON response containing an Access Token, for either Client IDs or Service Accounts
func (*AccessToken) IsSet ¶
func (a *AccessToken) IsSet() bool
IsSet method will check whether the Access Token value is set or not, returning a boolean (true / false) accordingly
func (*AccessToken) PrintLong ¶
func (a *AccessToken) PrintLong()
PrintLong method will output a more verbose message when the Access Token is about to be returned to the user
func (*AccessToken) PrintShort ¶
func (a *AccessToken) PrintShort()
PrintShort method will output strictly the Access Token, without line feeds. This might be especially useful when feeding the value into another program or app (like a cURL HTTP request)
type ClientID ¶
type ClientID struct { Type string ID string Secret string Scopes string RefreshToken *RefreshToken AccessToken *AccessToken }
ClientID struct will represent a Client ID object
func NewClientID ¶
NewClientID function will generate a Client ID based on the input parameters provided
func (*ClientID) Gen ¶
func (c *ClientID) Gen()
Gen method will initiate the process of creating an Access Code (by having the user visiting an authorization page), and with doing so creating a Refresh Token for this request
func (*ClientID) InitToken ¶
func (c *ClientID) InitToken()
InitToken method initiates the tokens in a Client ID, so that their methods can be accessed later on
func (*ClientID) Refresh ¶
func (c *ClientID) Refresh()
Refresh method will create a new Access Token based on a valid combination of credentials and refresh token values
type JWT ¶
JWT struct will define the contents of a JWT object
func (*JWT) Build ¶
Build method creates a JWT header and claim, signs it, and returns a JWT payload for the request
func (*JWT) InitHeader ¶
func (j *JWT) InitHeader()
InitHeader method defines the JWT's header value
type JWTClaim ¶
type JWTClaim struct { Issuer string `json:"iss,omitempty"` Subscriber string `json:"sub,omitempty"` Scope string `json:"scope,omitempty"` Audience string `json:"aud,omitempty"` Expiry int64 `json:"exp,omitempty"` Issued int64 `json:"iat,omitempty"` }
JWTClaim struct will represent the JWT body structure
func (*JWTClaim) SetAudience ¶
SetAudience method defines the JWTClaim's audience value
func (*JWTClaim) SetExpiry ¶
func (c *JWTClaim) SetExpiry()
SetExpiry method defines the Token's issuing and expiry time
func (*JWTClaim) SetSubscriber ¶
SetSubscriber method defines the JWTClaim's subscriber value
type RefreshToken ¶
RefreshToken struct will represent a Refresh Token object
func (*RefreshToken) GetAccessCode ¶
func (r *RefreshToken) GetAccessCode() string
GetAccessCode method retuns the Access Code value from the RefreshToken object
func (*RefreshToken) GetAuthURL ¶
func (r *RefreshToken) GetAuthURL() string
GetAuthURL method returns the auth URL from the RefreshToken object
func (*RefreshToken) GetToken ¶
func (r *RefreshToken) GetToken() string
GetToken method returns the Refresh Token from the RefreshToken object
func (*RefreshToken) GetTokenURL ¶
func (r *RefreshToken) GetTokenURL() string
GetTokenURL method returns the token URL from the RefreshToken object
func (*RefreshToken) HasToken ¶
func (r *RefreshToken) HasToken() bool
HasToken method check whether the Refresh Token value is set from a RefreshToken object, returning a boolean
func (*RefreshToken) SetAccessCode ¶
func (r *RefreshToken) SetAccessCode(input string)
SetAccessCode method will define the access code for the RefreshToken object
func (*RefreshToken) SetAuthURL ¶
func (r *RefreshToken) SetAuthURL(c *ClientID)
SetAuthURL method will define the auth URL for the RefreshToken object
func (*RefreshToken) SetToken ¶
func (r *RefreshToken) SetToken(input string)
SetToken method will define the Refresh Token value for the RefreshToken object
func (*RefreshToken) SetTokenURL ¶
func (r *RefreshToken) SetTokenURL()
SetTokenURL method will define the token URL for the RefreshToken object
type ServiceAccount ¶
type ServiceAccount 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"` AuthProvCertURL string `json:"auth_provider_x509_cert_url,omitempty"` ClientCertURL string `json:"client_x509_cert_url,omitempty"` JWT *JWT AccessToken *AccessToken }
ServiceAccount struct represents a service account object based on the provided JSON key file from GCP
func NewServiceAccount ¶
func NewServiceAccount(file, scope, sub string) *ServiceAccount
NewServiceAccount function creates a new ServiceAccount object based on the input parameters
func (*ServiceAccount) Auth ¶
func (s *ServiceAccount) Auth()
Auth method will issue a request for an Access Token, based on the created JWT
func (*ServiceAccount) GetClientID ¶
func (s *ServiceAccount) GetClientID() string
GetClientID method returns the ServiceAccount's associated ClientID (Workspace Domain-wide Delegation)
func (*ServiceAccount) GetEmail ¶
func (s *ServiceAccount) GetEmail() string
GetEmail method returns the ServiceAccount's defined service account email
func (*ServiceAccount) GetPrivateKey ¶
func (s *ServiceAccount) GetPrivateKey() string
GetPrivateKey method returns the ServiceAccount's defined Private Key
func (*ServiceAccount) GetTokenURI ¶
func (s *ServiceAccount) GetTokenURI() string
GetTokenURI method returns the ServiceAccount's defined token URI
func (*ServiceAccount) Init ¶
func (s *ServiceAccount) Init(scope, sub string)
Init method will initiate a ServiceAccount object by creating (and signing) the JWT for the request
func (*ServiceAccount) SetToken ¶
func (s *ServiceAccount) SetToken(body []byte)
SetToken method will define the AccessToken object in the calling ServiceAccount
type TokenError ¶
type TokenError struct { Error string `json:"error"` Description string `json:"error_description"` }
TokenError represents a JSON response containing an error when requesting an Access Token