#Deprecated in favor of uaa-go-client We are no longer actively maintaining this repository.
##CF UAA Token Fetcher A go library for getting oauth tokens (client credentials flow) from CF UAA.
- It caches access token until its expiration and returns the cached token unless otherwise specified
- It retries multiple times fresh token when either
- UAA is unreachable
- UAA returns 5xx status code
Usage:
- Create the OAuth parameters:
type OAuthConfig struct {
TokenEndpoint string `yaml:"token_endpoint"`
ClientName string `yaml:"client_name"`
ClientSecret string `yaml:"client_secret"`
Port int `yaml:"port"`
}
- Create the caching and retry configuration:
type TokenFetcherConfig struct {
MaxNumberOfRetries uint32
RetryInterval time.Duration
ExpirationBufferTime int64
}
- Invoke the
NewTokenFetcher
, passing the required parameters: This pointer is passed into theNewTokenFetcher
function
func NewTokenFetcher(
logger lager.Logger,
config *OAuthConfig,
tokenFetcherConfig TokenFetcherConfig,
clock clock.Clock) (TokenFetcher, error)
- To use the
TokenFetcher
, simply callFetchToken
, indicating if it can use a previously cached token or it should fetch a new token from UAA.
token, err := fetcher.FetchToken(true)
the Token
has an AccessTime string
and an ExpireTime int
.