client

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SetOauth2AuthStyle = func(authStyle oauth2.AuthStyle) Option {
	return func(c *Client) {
		c.oauthConfig.Endpoint.AuthStyle = authStyle
	}
}
View Source
var SetSuccessMessage = func(successMessage string) Option {
	return func(c *Client) {
		c.customMessages[oidcStatusSuccess] = successMessage
	}
}

Functions

func MarshalOptNoRefresh

func MarshalOptNoRefresh(t *Token)

Disables the refresh oauth flow

Types

type Claims

type Claims struct {
	Issuer                string   `json:"iss"`
	Audience              string   `json:"aud"`
	Subject               string   `json:"sub"`
	Name                  string   `json:"name"`
	AuthenticationMethods []string `json:"amr"`
	Email                 string   `json:"email"`
}

Claims represent the oidc token claims

type Client

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

Client is an oauth client

func NewClient

func NewClient(ctx context.Context, config *Config, clientOptions ...Option) (*Client, error)

NewClient returns a new client

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context) (*Token, error)

Authenticate will authenticate authenticate with the idp

func (*Client) Exchange

func (c *Client) Exchange(ctx context.Context, code string, codeVerifier string) (*oauth2.Token, error)

Exchange will exchange a token

func (*Client) GetAuthCodeURL

func (c *Client) GetAuthCodeURL(oauthMaterial *oauthMaterial) string

GetAuthCodeURL gets the url to the oauth2 consent page

func (*Client) RefreshToken

func (c *Client) RefreshToken(ctx context.Context, oldToken *Token) (*Token, error)

RefreshToken will fetch a new token

func (*Client) ValidateState

func (c *Client) ValidateState(ourState []byte, otherState []byte) error

ValidateState validates the state from the authorize request

func (*Client) Verify

func (c *Client) Verify(ctx context.Context, ourNonce []byte, rawIDToken string) (*oidc.IDToken, error)

Verify verifies an oidc id token

type Config

type Config struct {
	ClientID  string
	IssuerURL string

	ServerConfig *ServerConfig
}

Config is required to config a client

type MarshalOpts

type MarshalOpts func(*Token)

MarshalOpts changes a token for marshaling

type Option

type Option func(*Client)

type ServerConfig

type ServerConfig struct {
	FromPort int
	ToPort   int
	Timeout  time.Duration
}

ServerConfig is a server config

func (*ServerConfig) Validate

func (c *ServerConfig) Validate() error

Validate validates the config

type Token

type Token struct {
	Version int

	Expiry time.Time `json:"expires,omitempty"`

	IDToken      string `json:"token,omitempty"`
	AccessToken  string `json:"access_token,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	Claims       Claims `json:"claims,omitempty"`
}

Token wraps the extracted claims, auth token, id token, refresh token so we can easily use it throughout our application

func TokenFromString

func TokenFromString(tokenString *string, opts ...MarshalOpts) (*Token, error)

func (*Token) IsFresh

func (vt *Token) IsFresh() bool

func (*Token) Marshal

func (vt *Token) Marshal(opts ...MarshalOpts) (string, error)

Jump to

Keyboard shortcuts

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