oauth2

package
v1.76.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	UserEmail string

	Storage *TokenStore
}

Auth is XOAUTH2 implementation of smtp.Auth interface.

func (*Auth) Next

func (auth *Auth) Next(fromServer []byte, more bool) (toServer []byte, err error)

Next sends empty response to solve SASL challenge if response code is 334.

func (*Auth) Start

func (auth *Auth) Start(server *smtp.ServerInfo) (proto string, toServer []byte, err error)

Start returns proto and auth credentials for first auth msg.

type Credentials

type Credentials struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	TokenURI     string `json:"token_uri"`
}

Credentials represents OAuth2 credentials.

type Token

type Token struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	Type         string    `json:"token_type"`
	Expiry       time.Time `json:"expiry"`
}

Token represents OAuth2 token.

func RefreshToken

func RefreshToken(ctx context.Context, creds Credentials, refreshToken string) (_ *Token, err error)

RefreshToken is a helper method that refreshes token with given credentials and OUATH2 refresh token.

type TokenStore

type TokenStore struct {
	// contains filtered or unexported fields
}

TokenStore is a thread safe storage for OAuth2 token and credentials.

func NewTokenStore

func NewTokenStore(creds Credentials, token Token) *TokenStore

NewTokenStore creates new instance of token storage.

func (*TokenStore) Token

func (s *TokenStore) Token(ctx context.Context) (_ *Token, err error)

Token retrieves token in a thread safe way and refreshes it if needed.

Jump to

Keyboard shortcuts

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