oauth2x

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package oauth2x contains utilities for building OAuth 2 clients and servers.

Index

Constants

View Source
const (
	// KeySize is the size of the encryption key.
	KeySize = 32
)

Variables

This section is empty.

Functions

func BrowserTokenSource

func BrowserTokenSource(
	conf *oauth2.Config,
	callbackHostPort netx.HostPort,
	opts *BrowserTokenSourceOptions,
) (oauth2.TokenSource, error)

A BrowserTokenSource retrieves tokens from an OAuth2 provider that presents a consent page in the local browser. Useful for acquiring credentials

func CachingTokenSource

func CachingTokenSource(
	cache TokenCache, fallback oauth2.TokenSource,
	log *zap.Logger, clock clockwork.Clock,
) oauth2.TokenSource

A CachingTokenSource retrieves tokens from a cache, and if that fails triggers consults another token source.

Types

type BrowserTokenSourceOptions

type BrowserTokenSourceOptions struct {
	Log             *zap.Logger
	SuccessTemplate string
	ErrorTemplate   string
	Timeout         time.Duration
}

BrowserTokenSourceOptions are options to creating a BrowserTokenSource

type TokenCache

type TokenCache interface {
	Load() ([]byte, error)
	Store([]byte) error
	Name() string
}

A TokenCache is a cache for local tokens.

func EncryptTokenCache

func EncryptTokenCache(cache TokenCache, key [KeySize]byte) TokenCache

EncryptTokenCache wraps a token cache with an encryption layer.

func NewFileTokenCache

func NewFileTokenCache(filename string) TokenCache

NewFileTokenCache returns a TokenCache that writes to a file.

type TokenSourceFunc

type TokenSourceFunc func() (*oauth2.Token, error)

TokenSourceFunc is a function that returns a token and can act as an oauth2.TokenSource.

func (TokenSourceFunc) Token

func (fn TokenSourceFunc) Token() (*oauth2.Token, error)

Token returns the token by calling the function.

Jump to

Keyboard shortcuts

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