oauthclient

package
v0.0.0-...-60b8695 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 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

type Callback func(echo.Context, *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:"-"`

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

Config is the configuration for the OAuth client.

type OAuth2AuthCodeURLOptionsProvider

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

OAuth2AuthCodeURLOptionsProvider provides OAuth2 authorization URL options based on the context.

type OAuth2ConfigProvider

type OAuth2ConfigProvider func(echo.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(c echo.Context) error

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

func (*OAuthClient) HandleLogin

func (oc *OAuthClient) HandleLogin(c echo.Context) error

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

func (*OAuthClient) HandleLogout

func (oc *OAuthClient) HandleLogout(c echo.Context) error

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

func (*OAuthClient) HandleToken

func (oc *OAuthClient) HandleToken(c echo.Context) error

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 cookie is not there, it returns a 401 Unauthorized error.

func (*OAuthClient) StateCookie

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

StateCookie returns the cookie storing the state of the console.

type Option

type Option func(*OAuthClient)

Option is an OAuth2Client configuration option.

func WithAuthCodeURLOptions

func WithAuthCodeURLOptions(provider OAuth2AuthCodeURLOptionsProvider) Option

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

func WithCallback

func WithCallback(cb Callback) Option

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

func WithNextKey

func WithNextKey(key string) Option

WithNextKey overrides the default query parameter used for callback return.

func WithOAuth2ConfigProvider

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