token_fetcher

package
v0.0.0-...-1ce3cd0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2015 License: Apache-2.0, BSD-2-Clause-Views, BSD-3-Clause, + 1 more Imports: 8 Imported by: 0

README

#CF UAA Token Fetcher A little go library for getting oauth tokens from CF UAA


Usage:

Given the parameters needed to fill the OAuthConfig struct:

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

Create a pointer to the OAuthConfig

This pointer is passed into the NewTokenFetcher function

func NewTokenFetcher(config *OAuthConfig) *Fetcher {
	return &Fetcher{
		config: config,
		client: &http.Client{},
	}
}

To use the TokenFetcher after passing in your OAuthConfig, simply call FetchToken

fetcher := NewTokenFetcher(cfg)
token, err := fetcher.FetchToken()

the Token has an AccessTime string and an ExpireTime int. You can use the ExpireTime to trigger requesting a new token.

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 NewTokenFetcher

func NewTokenFetcher(config *OAuthConfig) *Fetcher

func (*Fetcher) FetchToken

func (f *Fetcher) FetchToken() (*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"`
	ExpireTime  int    `json:"expires_in"`
}

type TokenFetcher

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

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