oauthclient

package
v3.32.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback added in v3.9.1

type Callback func(http.ResponseWriter, *http.Request, *oauth2.Token, string) error

Callback occurs after the OAuth2 token exchange has been performed successfully.

type Config

type Config struct {
	AuthorizeURL string `name:"authorize-url" description:"The OAuth Authorize URL"`
	LogoutURL    string `name:"logout-url" description:"The OAuth Logout URL"`
	TokenURL     string `name:"token-url" description:"The OAuth Token Exchange URL"`
	RootURL      string `name:"-"`

	ClientID     string `name:"client-id" description:"The OAuth client ID"`
	ClientSecret string `name:"client-secret" description:"The OAuth client secret" json:"-"`

	CrossSiteCookie bool `name:"cross-site-cookie" description:"Whether to make OAuth cookies accessible cross-site"`

	StateCookieName string `name:"-"`
	AuthCookieName  string `name:"-"`
	// contains filtered or unexported fields
}

Config is the configuration for the OAuth client.

type OAuth2AuthCodeURLOptionsProvider added in v3.11.0

type OAuth2AuthCodeURLOptionsProvider func(context.Context) ([]oauth2.AuthCodeOption, error)

OAuth2AuthCodeURLOptionsProvider provides OAuth2 authorization URL options based on the context.

type OAuth2ConfigProvider added in v3.9.1

type OAuth2ConfigProvider func(context.Context) (*oauth2.Config, error)

OAuth2ConfigProvider provides an OAuth2 client config based on the context.

type OAuthClient

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

OAuthClient is the OAuth client component.

func New

func New(c *component.Component, config Config, opts ...Option) (*OAuthClient, error)

New returns a new OAuth client instance.

func (*OAuthClient) AuthCookie

func (oc *OAuthClient) AuthCookie() *cookie.Cookie

AuthCookie returns a new authCookie.

func (*OAuthClient) HandleCallback

func (oc *OAuthClient) HandleCallback(w http.ResponseWriter, r *http.Request)

HandleCallback is a handler that takes the auth code and exchanges it for the access token.

func (*OAuthClient) HandleLogin

func (oc *OAuthClient) HandleLogin(w http.ResponseWriter, r *http.Request)

HandleLogin is the handler for redirecting the user to the authorization endpoint.

func (*OAuthClient) HandleLogout

func (oc *OAuthClient) HandleLogout(w http.ResponseWriter, r *http.Request)

HandleLogout invalidates the user's authorization, removes the auth cookie and may provide a URL to logout of the OAuth provider as well.

func (*OAuthClient) HandleToken

func (oc *OAuthClient) HandleToken(w http.ResponseWriter, r *http.Request)

HandleToken is a handler that returns a valid OAuth token. It reads the token from the authorization cookie and refreshes it if needed. If the authorization cookie is not there, it returns a 401 Unauthorized error.

func (*OAuthClient) Logout added in v3.19.1

func (oc *OAuthClient) Logout(ctx context.Context, token *oauth2.Token) (logoutURL string, err error)

Logout initiates the logout. Based on configuration, this method either returns a logout URL to redirect the user to complete the logout, or this method deletes the access token from the OAuth server.

func (*OAuthClient) StateCookie

func (oc *OAuthClient) StateCookie() *cookie.Cookie

StateCookie returns the cookie storing the state of the console.

func (*OAuthClient) Token added in v3.19.1

func (oc *OAuthClient) Token(ctx context.Context, token *oauth2.Token) (*oauth2.Token, error)

Token returns the OAuth 2.0 token. If the given token is about to expire, this method refreshes the token and returns the new token.

type Option added in v3.9.1

type Option func(*OAuthClient)

Option is an OAuth2Client configuration option.

func WithAuthCodeURLOptions added in v3.11.0

func WithAuthCodeURLOptions(provider OAuth2AuthCodeURLOptionsProvider) Option

WithAuthCodeURLOptions changes the OAuth2 authorization URL options provided to the oauth2 package.

func WithCallback added in v3.9.1

func WithCallback(cb Callback) Option

WithCallback adds a callback to be executed at the end of the OAuth2 token exchange.

func WithNextKey added in v3.9.1

func WithNextKey(key string) Option

WithNextKey overrides the default query parameter used for callback return.

func WithOAuth2ConfigProvider added in v3.9.1

func WithOAuth2ConfigProvider(provider OAuth2ConfigProvider) Option

WithOAuth2ConfigProvider overrides the default OAuth2 configuration provider.

Jump to

Keyboard shortcuts

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