go4.org: go4.org/oauthutil Index | Files

package oauthutil

import "go4.org/oauthutil"

Package oauthutil contains OAuth 2 related utilities.

Index

Package Files

oauth.go

Constants

const TitleBarRedirectURL = "urn:ietf:wg:oauth:2.0:oob"

TitleBarRedirectURL is the OAuth2 redirect URL to use when the authorization code should be returned in the title bar of the browser, with the page text prompting the user to copy the code and paste it in the application.

Variables

var ErrNoAuthCode = errors.New("oauthutil: unspecified TokenSource.AuthCode")

ErrNoAuthCode is returned when Token() has not found any valid cached token and TokenSource does not have an AuthCode for getting a new token.

func NewRefreshTokenSource Uses

func NewRefreshTokenSource(config *oauth2.Config, refreshToken string) oauth2.TokenSource

NewRefreshTokenSource returns a token source that obtains its initial token based on the provided config and the refresh token.

type TokenSource Uses

type TokenSource struct {
    Config *oauth2.Config

    // CacheFile is where the token will be stored JSON-encoded. Any call to Token
    // first tries to read a valid token from CacheFile.
    CacheFile string

    // AuthCode provides the authorization code that Token will exchange for a token.
    // It usually is a way to prompt the user for the code. If CacheFile does not provide
    // a token and AuthCode is nil, Token returns ErrNoAuthCode.
    AuthCode func() string
}

TokenSource is an implementation of oauth2.TokenSource. It uses CacheFile to store and reuse the the acquired token, and AuthCode to provide the authorization code that will be exchanged for a token otherwise.

func (TokenSource) Token Uses

func (src TokenSource) Token() (*oauth2.Token, error)

Token first tries to find a valid token in CacheFile, and otherwise uses Config and AuthCode to fetch a new token. This new token is saved in CacheFile (if not blank). If CacheFile did not provide a token and AuthCode is nil, ErrNoAuthCode is returned.

Package oauthutil imports 6 packages (graph) and is imported by 15 packages. Updated 2018-01-03. Refresh now. Tools for package owners.