tokensource

package module
v0.0.0-...-29566af Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: MIT Imports: 12 Imported by: 2

README

tokensource

This repository contains some oauth2.TokenSource.

AsyncRefreshingTokenSource

This TokenSource refreshes the token asynchronously to avoid blocking.

refs: https://qiita.com/kazegusuri/items/b6123f9d3e0777d0750c#reusetokensource%E3%81%AF%E3%83%96%E3%83%AD%E3%83%83%E3%82%AF%E3%81%99%E3%82%8B

SmartIDTokenSource SmartIDTokenSource

(DEPRECATED) They have moved to https://github.com/apstndb/adcplus.

They perform ADC. Additionally, they perform impersonation when CLOUDSDK_AUTH_IMPERSONATE_SERVICE_ACCOUNT is set.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsyncRefreshingTokenSource

func AsyncRefreshingTokenSource(ctx context.Context, conf AsyncRefreshingConfig, genFunc func(ctx context.Context) (oauth2.TokenSource, error)) (oauth2.TokenSource, error)

AsyncRefreshingTokenSource create TokenSource with the refresh config conf and the TokenSource generator function genFunc. genFunc will be called to generate the one-time TokenSource instance every time to refresh. Note: AsyncRefreshingTokenSource fetches the first token synchronously.

func SmartAccessTokenSource

func SmartAccessTokenSource(ctx context.Context, scopes ...string) (oauth2.TokenSource, error)

SmartAccessTokenSource generate oauth2.TokenSource which generates access token and supports CLOUDSDK_AUTH_IMPERSONATE_SERVICE_ACCOUNT environment variable.

func SmartIDTokenSource

func SmartIDTokenSource(ctx context.Context, audience string) (oauth2.TokenSource, error)

SmartIDTokenSource generate oauth2.TokenSource which generates ID token and supports CLOUDSDK_AUTH_IMPERSONATE_SERVICE_ACCOUNT environment variable.

Types

type AsyncRefreshingConfig

type AsyncRefreshingConfig struct {
	// MarginBeforeExpiry is the margin for refreshing the token before Expiry.
	// If it is zero value, TokenSource don't care about Expiry.
	MarginBeforeExpiry time.Duration
	// RandomizationFactorForRefreshInterval is randomization factor for MarginBeforeExpiry.
	RandomizationFactorForMarginBeforeExpiry float64

	// RefreshInterval is interval for refreshing token if Expiry based refreshing is not applied.
	// If not set, 30 minutes is default interval.
	RefreshInterval time.Duration
	// RandomizationFactorForRefreshInterval is randomization factor for RefreshInterval.
	RandomizationFactorForRefreshInterval float64

	// Backoff is backoff configuration for TokenSource.Token().
	// If not set, backoff.NewExponentialBackOff is used as the default value.
	// See also https://pkg.go.dev/github.com/cenkalti/backoff/v4#NewExponentialBackOff.
	// If IsRetryable isn't set, no backoff will be performed.
	Backoff backoff.BackOff

	// IsRetryable is the predicate function for retryable errors.
	// Default: never retry.
	IsRetryable func(err error) bool
}

AsyncRefreshingConfig is the refresh configuration of AsyncRefreshingTokenSource.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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