oauth2

package
v1.16.8 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: BSD-2-Clause-Patent Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SchemeBearer = "Bearer"
	SchemeToken  = "token"
)

Supported authentication schemes. Note that Gogs and Gitea use non-standard authorization schemes.

Variables

This section is empty.

Functions

func ContextTokenSource

func ContextTokenSource() scm.TokenSource

ContextTokenSource returns a TokenSource that returns a token from the http.Request context.

func StaticTokenSource

func StaticTokenSource(t *scm.Token) scm.TokenSource

StaticTokenSource returns a TokenSource that always returns the same token. Because the provided token t is never refreshed, StaticTokenSource is only useful for tokens that never expire.

Types

type Refresher

type Refresher struct {
	ClientID     string
	ClientSecret string
	Endpoint     string

	Source scm.TokenSource
	Client *http.Client
}

Refresher is an http.RoundTripper that refreshes oauth tokens, wrapping a base RoundTripper and refreshing the token if expired.

IMPORTANT the Refresher is NOT safe for concurrent use by multiple goroutines.

func (*Refresher) Refresh

func (t *Refresher) Refresh(token *scm.Token) error

Refresh refreshes the expired token.

func (*Refresher) Token

func (t *Refresher) Token(ctx context.Context) (*scm.Token, error)

Token returns a token. If the token is missing or expired, the token is refreshed.

type Transport

type Transport struct {
	Scheme string
	Source scm.TokenSource
	Base   http.RoundTripper
}

Transport is an http.RoundTripper that refreshes oauth tokens, wrapping a base RoundTripper and refreshing the token if expired.

func (*Transport) RoundTrip

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

RoundTrip authorizes and authenticates the request with an access token from the request context.

Jump to

Keyboard shortcuts

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