oauth

package
v0.0.0-...-aa54cbc Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

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

func NewClientID(id, secret, scopes, refreshToken string) (*ClientID, error)

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) GetID

func (c *ClientID) GetID() string

GetID method returns the Client ID value from a ClientID object

func (*ClientID) GetScopes

func (c *ClientID) GetScopes() string

GetScopes method returns the access scopes from a ClientID object

func (*ClientID) GetSecret

func (c *ClientID) GetSecret() string

GetSecret method returns the Client ID secret from a ClientID object

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

func (*ClientID) SetID

func (c *ClientID) SetID(input string)

SetID method will define the Client ID value for the ClientID object

func (*ClientID) SetScopes

func (c *ClientID) SetScopes(input string)

SetScopes method will define the access scopes for the ClientID object

func (*ClientID) SetSecret

func (c *ClientID) SetSecret(input string)

SetSecret method will define the Client ID secret for the ClientID object

func (*ClientID) SetToken

func (c *ClientID) SetToken(body []byte)

SetToken method will define the token values for Client IDs; setting the Access Token and Refresh Token values respectively

type JWT

type JWT struct {
	Header    []byte
	Claim     *JWTClaim
	Signature []byte
	Output    []byte
}

JWT struct will define the contents of a JWT object

func (*JWT) Build

func (j *JWT) Build() ([]byte, error)

Build method creates a JWT header and claim, signs it, and returns a JWT payload for the request

func (*JWT) GetOutput

func (j *JWT) GetOutput() string

GetOutput method returns the complete JWT string

func (*JWT) InitHeader

func (j *JWT) InitHeader()

InitHeader method defines the JWT's header value

func (*JWT) Sign

func (j *JWT) Sign(pkey string) ([]byte, error)

Sign method will create a signature for the JWT

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

func (c *JWTClaim) SetAudience(input string)

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) SetIssuer

func (c *JWTClaim) SetIssuer(input string)

SetIssuer method defines the JWTClaim's issuer value

func (*JWTClaim) SetScope

func (c *JWTClaim) SetScope(input string)

SetScope method defines the JWTClaim's header value

func (*JWTClaim) SetSubscriber

func (c *JWTClaim) SetSubscriber(input string)

SetSubscriber method defines the JWTClaim's subscriber value

type RefreshToken

type RefreshToken struct {
	AccessCode string
	AuthURL    string
	TokenURL   string
	Token      string
}

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

Jump to

Keyboard shortcuts

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