client

package
v0.0.0-...-730ab85 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextClient

func ContextClient(ctx context.Context) *http.Client

func NewClient

func NewClient(ctx context.Context, src Source) *http.Client

Types

type AuthCodeOption

type AuthCodeOption interface {
	// contains filtered or unexported methods
}
var (
	AccessTypeOnline  AuthCodeOption = SetAuthURLParam("access_type", "online")
	AccessTypeOffline AuthCodeOption = SetAuthURLParam("access_type", "offline")
	ApprovalForce     AuthCodeOption = SetAuthURLParam("prompt", "consent")
)

func SetAuthURLParam

func SetAuthURLParam(key, value string) AuthCodeOption

type AuthStyle

type AuthStyle int
const (
	AuthStyleInParams AuthStyle = 0
	AuthStyleInHeader AuthStyle = 1
)

type ContextKey

type ContextKey struct{}
var HTTPClient ContextKey

type Endpoint

type Endpoint struct {
	AuthURL  string
	TokenURL string
}

type Oauth2

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

func NewOauth2

func NewOauth2(opts *Options) *Oauth2

func (*Oauth2) AuthCodeURL

func (o *Oauth2) AuthCodeURL(state string, opts ...AuthCodeOption) string

func (*Oauth2) AuthorizationCodeToken

func (o *Oauth2) AuthorizationCodeToken(ctx context.Context, code string, opts ...AuthCodeOption) (*Token, error)

func (*Oauth2) Client

func (o *Oauth2) Client(ctx context.Context, t *Token) *http.Client

func (*Oauth2) ClientCredentialsToken

func (o *Oauth2) ClientCredentialsToken(ctx context.Context, opts ...AuthCodeOption) (*Token, error)

func (*Oauth2) PasswordCredentialsToken

func (o *Oauth2) PasswordCredentialsToken(ctx context.Context, username, password string) (*Token, error)

func (*Oauth2) StaticClient

func (o *Oauth2) StaticClient(ctx context.Context, accessToken string) *http.Client

func (*Oauth2) TokenSource

func (o *Oauth2) TokenSource(ctx context.Context, t *Token) Source

type Options

type Options struct {
	ClientID     string
	ClientSecret string
	Domain       string

	Endpoint    Endpoint
	RedirectURL string
	Scopes      []string
	AuthStyle   AuthStyle
}

type Source

type Source interface {
	Token() (*Token, error)
}

func NewTokenSource

func NewTokenSource(ctx context.Context, opt *Options, t *Token) Source

func ReuseTokenSource

func ReuseTokenSource(t *Token, src Source) Source

func StaticTokenSource

func StaticTokenSource(t *Token) Source

type Token

type Token struct {
	AccessToken  string    `json:"access_token"`
	TokenType    string    `json:"token_type,omitempty"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	Expiry       time.Time `json:"expiry,omitempty"`
	MacKey       string    `json:"mac_key,omitempty"`
	MacAlgorithm string    `json:"mac_algorithm,omitempty"`
	// contains filtered or unexported fields
}

func RequestToken

func RequestToken(ctx context.Context, opt *Options, v url.Values) (*Token, error)

func (*Token) SetAuthHeader

func (t *Token) SetAuthHeader(r *http.Request)

func (*Token) SetExt

func (t *Token) SetExt(ext string)

func (*Token) SetNonce

func (t *Token) SetNonce(nonce string)

func (*Token) SetTs

func (t *Token) SetTs(ts int64)

func (*Token) Type

func (t *Token) Type() string

func (*Token) Valid

func (t *Token) Valid() bool

type Transport

type Transport struct {
	Source Source
	Base   http.RoundTripper
}

func (*Transport) CancelRequest

func (t *Transport) CancelRequest(req *http.Request)

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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