Back to godoc.org

Package oauthclient

v3.9.4
Latest Go to latest

The latest major version is v3.

Published: Sep 23, 2020 | License: Apache-2.0 | Module: go.thethings.network/lorawan-stack/v3

Index

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 OAuth2ConfigProvider

type OAuth2ConfigProvider func(echo.Context) *oauth2.Config

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 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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier