oauthutil

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Overview

Package oauthutil provides helpers for working with OAuth 2.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingOAuthConfig is returned when OAuth configuration has not been provided.
	ErrMissingOAuthConfig = errors.New("missing OAuth config")
)
View Source
var (
	// ErrMissingOAuthToken is returned when OAuth token has not been provided.
	ErrMissingOAuthToken = errors.New("missing OAuth token")
)

Functions

func UserInfo

func UserInfo(ctx context.Context, config *oauth2.Config, token *oauth2.Token) (*oidcclaims.Claims, error)

UserInfo requests current information about the user.

Types

type FileStore

type FileStore struct {

	// Directory credentials are stored.
	Directory string

	// Filename of credential being used.
	Filename string
	// contains filtered or unexported fields
}

FileStore manages credentials locally.

func NewStore

func NewStore(ctx context.Context, headless bool, credentialDir, envName string) *FileStore

NewStore returns a FileStore with defaults set.

func (*FileStore) Claims

func (s *FileStore) Claims() (*oidcclaims.Claims, error)

Claims related to current token.

func (*FileStore) Login

func (s *FileStore) Login(loginOpts *LoginOptions) error

Login authorizes the user and writes their token to the FileStore.

func (*FileStore) Name

func (s *FileStore) Name() string

Name of the FileStore.

func (*FileStore) Token

func (s *FileStore) Token() (*oauth2.Token, error)

Token reads a token from the FileStore.

func (*FileStore) UpdateUserInfo

func (s *FileStore) UpdateUserInfo() error

UpdateUserInfo sets data returned by userinfo as claims.

type LoginOptions

type LoginOptions struct {
	ListenAddr     string
	OAuth          *oauth2.Config
	NoPKCE         bool
	NoRefreshToken bool
}

LoginOptions contain the configuration for the Authorize command.

func NewLoginOptions

func NewLoginOptions() *LoginOptions

NewLoginOptions returns LoginOptions with defaults set.

type PKCEVerifier added in v1.0.1

type PKCEVerifier authhandler.PKCEParams

PKCEVerifier is a OAuth2 PKCE code verifier.

func Login

func Login(opts *LoginOptions) (code string, verifier *PKCEVerifier, err error)

Login prompts users to authenticate with a browser.

func NewPKCEVerifier added in v1.0.1

func NewPKCEVerifier() *PKCEVerifier

NewPKCEVerifier returns a new code verifier.

func (*PKCEVerifier) AuthOpts added in v1.0.1

func (v *PKCEVerifier) AuthOpts() []oauth2.AuthCodeOption

AuthOpts returns the options to be passed to the OAuth2 authorization code flow from params.

func (*PKCEVerifier) TokenOpt added in v1.0.1

func (v *PKCEVerifier) TokenOpt() oauth2.AuthCodeOption

TokenOpt returns the options to be passed in the OAuth2 token exchange.

type Store

type Store interface {
	oauth2.TokenSource
	Name() string
	Login(loginOpts *LoginOptions) error
	Claims() (*oidcclaims.Claims, error)
	UpdateUserInfo() error
}

Store allows for login and accessing Tokens.

Jump to

Keyboard shortcuts

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