tokensource

package
v1.70.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Package tokensource has a Golang OAuth2 Token Source that notifies the refresh operations.

This is useful to react to those events and store the new token in your database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Notify

type Notify struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

Notify is an oauth2.TokenSource that tracks changes in the token to be able to store the updated token after finishing the operations.

func NewNotify

func NewNotify(ctx context.Context, config *oauth2.Config, token *oauth2.Token) *Notify

NewNotify builds a new oauth2.TokenSource that alerts when a token changes when calling HasChanged() after finishing all calls.

func NewNotifyHook

func NewNotifyHook(ctx context.Context, config *oauth2.Config, token *oauth2.Token, hook UpdateHook) *Notify

NewNotifyHook builds a new oauth2.TokenSource that alerts when a token changes through a hook that will be called when it happens.

func (*Notify) Client

func (notify *Notify) Client(ctx context.Context) *http.Client

Client builds an OAuth2-authenticated HTTP client like oauth2.Config.Client does.

func (*Notify) HasChanged

func (notify *Notify) HasChanged() bool

HasChanged returns if we have a new token different from the one passed to NewNotify.

func (*Notify) Token

func (notify *Notify) Token() (*oauth2.Token, error)

Token implements oauth2.TokenSource returning a refreshed token if needed. Any update will be registered to make HasChanged() return true. It is threadsafe as the library requires.

type UpdateHook

type UpdateHook func(token *oauth2.Token) error

UpdateHook is a function that can be passed to the constructor that will be called when the token updates.

Jump to

Keyboard shortcuts

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