token_fetcher

package
v0.0.0-...-b61aaf9 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2016 License: Apache-2.0, BSD-2-Clause-Views, BSD-3-Clause, + 1 more Imports: 12 Imported by: 0

README

#CF UAA Token Fetcher A go library for getting oauth tokens (client credentials flow) from CF UAA.

  1. It caches access token until its expiration and returns the cached token unless otherwise specified
  2. It retries multiple times fresh token when either
    1. UAA is unreachable
    2. 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 the NewTokenFetcher function
func NewTokenFetcher(
	logger lager.Logger,
	config *OAuthConfig,
	tokenFetcherConfig TokenFetcherConfig,
	clock clock.Clock) (TokenFetcher, error)
  • To use the TokenFetcher, simply call FetchToken, 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fetcher

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

func (*Fetcher) FetchToken

func (f *Fetcher) FetchToken(useCachedToken bool) (*Token, error)

type NoOpTokenFetcher

type NoOpTokenFetcher struct {
}

func (*NoOpTokenFetcher) FetchToken

func (f *NoOpTokenFetcher) FetchToken(useCachedToken bool) (*Token, error)

type OAuthConfig

type OAuthConfig struct {
	TokenEndpoint string `yaml:"token_endpoint"`
	ClientName    string `yaml:"client_name"`
	ClientSecret  string `yaml:"client_secret"`
	Port          int    `yaml:"port"`
}

type Token

type Token struct {
	AccessToken string `json:"access_token"`
	// Expire time in seconds
	ExpireTime int64 `json:"expires_in"`
}

type TokenFetcher

type TokenFetcher interface {
	FetchToken(useCachedToken bool) (*Token, error)
}

func NewNoOpTokenFetcher

func NewNoOpTokenFetcher() TokenFetcher

func NewTokenFetcher

func NewTokenFetcher(logger lager.Logger, config *OAuthConfig, tokenFetcherConfig TokenFetcherConfig, clock clock.Clock) (TokenFetcher, error)

type TokenFetcherConfig

type TokenFetcherConfig struct {
	MaxNumberOfRetries   uint32
	RetryInterval        time.Duration
	ExpirationBufferTime int64
}

Directories

Path Synopsis
This file was generated by counterfeiter
This file was generated by counterfeiter

Jump to

Keyboard shortcuts

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