oauth2utils

package module
v0.0.0-...-a2c588e Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 6 Imported by: 0

README

go-oauth2utils

Go OAuth2 utils.

GoDoc

Install

go get github.com/koofr/go-oauth2utils

Testing

go test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReactiveTokenSource

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

ReactiveTokenSource is a TokenSource that holds a single token in memory and validates its expiry before each call to retrieve it with Token. If it's expired, it will be auto-refreshed using the new TokenSource and onUpdate callback will be called with new token.

func NewReactiveTokenSource

func NewReactiveTokenSource(
	tokenSourceFactory TokenSourceFactory,
	t *oauth2.Token,
	onUpdate func(ctx context.Context, t *oauth2.Token),
) *ReactiveTokenSource

NewReactiveTokenSource returns a ReactiveTokenSource which repeatedly returns the same token as long as it's valid, starting with t. When its cached token is invalid, a new token is obtained from src and onUpdate callback is called.

func (*ReactiveTokenSource) Token

Token returns the current token if it's still valid, else will refresh the current token (using r.Context for HTTP client information) and return the new one.

type TokenSource

type TokenSource interface {
	Token(ctx context.Context) (*oauth2.Token, error)
}

type TokenSourceFactory

type TokenSourceFactory func(ctx context.Context, t *oauth2.Token) oauth2.TokenSource

type Transport

type Transport struct {
	// Source supplies the token to add to outgoing requests'
	// Authorization headers.
	Source TokenSource

	// Base is the base RoundTripper used to make HTTP requests.
	// If nil, http.DefaultTransport is used.
	Base http.RoundTripper
	// contains filtered or unexported fields
}

Transport is an http.RoundTripper that makes OAuth 2.0 HTTP requests, wrapping a base RoundTripper and adding an Authorization header with a token from the supplied Sources.

Transport is a low-level mechanism. Most code will use the higher-level Config.Client method instead.

func (*Transport) CancelRequest

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

CancelRequest cancels an in-flight request by closing its connection.

func (*Transport) RoundTrip

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

RoundTrip authorizes and authenticates the request with an access token from Transport's Source.

Jump to

Keyboard shortcuts

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