oauthutil

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: Apache-2.0 Imports: 18 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 Login

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

Login prompts users to authenticate with a browser.

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
}

FileStore manages credentials locally.

func NewStore

func NewStore(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(ctx context.Context, 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(ctx context.Context) error

UpdateUserInfo sets data returned by userinfo as claims.

type LoginOptions

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

LoginOptions contain the configuration for the Authorize command.

func NewLoginOptions

func NewLoginOptions() *LoginOptions

NewLoginOptions returns LoginOptions with defaults set.

type Store

type Store interface {
	oauth2.TokenSource
	Name() string
	Login(ctx context.Context, loginOpts *LoginOptions) error
	Claims() (*oidcclaims.Claims, error)
	UpdateUserInfo(ctx context.Context) 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