Documentation ¶
Index ¶
- type Callback
- type Config
- type OAuth2AuthCodeURLOptionsProvider
- type OAuth2ConfigProvider
- type OAuthClient
- func (oc *OAuthClient) AuthCookie() *cookie.Cookie
- func (oc *OAuthClient) HandleCallback(w http.ResponseWriter, r *http.Request)
- func (oc *OAuthClient) HandleLogin(w http.ResponseWriter, r *http.Request)
- func (oc *OAuthClient) HandleLogout(w http.ResponseWriter, r *http.Request)
- func (oc *OAuthClient) HandleToken(w http.ResponseWriter, r *http.Request)
- func (oc *OAuthClient) Logout(ctx context.Context, token *oauth2.Token) (logoutURL string, err error)
- func (oc *OAuthClient) StateCookie() *cookie.Cookie
- func (oc *OAuthClient) Token(ctx context.Context, token *oauth2.Token) (*oauth2.Token, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Callback ¶ added in v3.9.1
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
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 (*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.
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
WithCallback adds a callback to be executed at the end of the OAuth2 token exchange.
func WithNextKey ¶ added in v3.9.1
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.