Documentation ¶
Index ¶
- Constants
- type OAuth2Token
- func (token *OAuth2Token) Deserialize(data []byte) error
- func (token *OAuth2Token) DeserializeEncrypted(data []byte, key []byte) error
- func (token *OAuth2Token) GetAccessToken(expirationThreshold float64) string
- func (token *OAuth2Token) IsExpired(expirationThreshold float64) bool
- func (token *OAuth2Token) Refresh()
- func (token *OAuth2Token) Scopes() []string
- func (token *OAuth2Token) Serialize() ([]byte, error)
- func (token *OAuth2Token) SerializeEncrypted(key []byte) ([]byte, error)
- type OAuthAPIConnectionData
Constants ¶
const OAuth2AuthEndpoint = "https://accounts.google.com/o/oauth2/v2/auth"
const OAuth2TokenEndpoint = "https://oauth2.googleapis.com/token"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OAuth2Token ¶
type OAuth2Token struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` Expiration float64 `json:"expires_in"` IdToken string `json:"id_token"` Scope string `json:"scope"` TokenType string `json:"token_type"` LastRefresh time.Time ConnectionData OAuthAPIConnectionData }
The Token data. Use the AccessToken to access Google Apps APIs.
func GetOAuth2Token ¶
func GetOAuth2Token(data OAuthAPIConnectionData) (*OAuth2Token, error)
Get an OAuth2 Token with the connection data specified
func (*OAuth2Token) Deserialize ¶
func (token *OAuth2Token) Deserialize(data []byte) error
Deserialize the token.
Use DeserializeEncrypted for safety.
func (*OAuth2Token) DeserializeEncrypted ¶
func (token *OAuth2Token) DeserializeEncrypted(data []byte, key []byte) error
Deserialize the encrypted token with a key.
Key must be <= 32 bytes.
func (*OAuth2Token) GetAccessToken ¶
func (token *OAuth2Token) GetAccessToken(expirationThreshold float64) string
Get the access token, refreshing it automatically if it is expired.
expirationThreshold - Threshold before actual expiration in seconds after which the token will count as being expired, even if not actually expired
func (*OAuth2Token) IsExpired ¶
func (token *OAuth2Token) IsExpired(expirationThreshold float64) bool
Used to see if the Token is expired. You can use this with Refresh() to refresh the token. Or just use GetAccessToken.
expirationThreshold - Threshold before actual expiration in seconds after which the token will count as being expired, even if not actually expired
func (*OAuth2Token) Scopes ¶
func (token *OAuth2Token) Scopes() []string
Used to get scopes as a string slice.
func (*OAuth2Token) Serialize ¶
func (token *OAuth2Token) Serialize() ([]byte, error)
Serialize the token to a byte slice.
Use SerializeEncrypted for security.
func (*OAuth2Token) SerializeEncrypted ¶
func (token *OAuth2Token) SerializeEncrypted(key []byte) ([]byte, error)
Serialize the token while encrypting it with a key.
Key must be <= 32 bytes.
type OAuthAPIConnectionData ¶
The connection data used to connect to Google's OAuth2 API. ClientId and ClientSecret can be taken from your developer dashboard.
https://developers.google.com/identity/protocols/oauth2/scopes