Documentation
¶
Index ¶
- Constants
- func NewNonce() (string, error)
- func NewState() (string, error)
- type AuthCodeFlowOpts
- type Client
- type Clock
- type Config
- type GetTokenByAuthCodeOpts
- type Listener
- type NoAvailablePortError
- type OIDCClient
- func (c *OIDCClient) ClientSecret() string
- func (c *OIDCClient) DeviceAuth(ctx context.Context) (*oauth2.DeviceAuthResponse, error)
- func (c *OIDCClient) GetTokenByAuthCode(ctx context.Context, ops GetTokenByAuthCodeOpts, ...) (*Token, error)
- func (c *OIDCClient) GetTokenByClientCredentials(ctx context.Context) (*Token, error)
- func (c *OIDCClient) GetTokenByDeviceCode(ctx context.Context, resp *oauth2.DeviceAuthResponse) (*Token, error)
- func (c *OIDCClient) GetTokenByDeviceCodeManual(ctx context.Context, resp *oauth2.DeviceAuthResponse) (*Token, error)
- func (c *OIDCClient) GetTokenByPassword(ctx context.Context, username string, password string) (*Token, error)
- func (c *OIDCClient) Refresh(ctx context.Context, refreshToken string) (*Token, error)
- func (c *OIDCClient) SetClientSecret(s string)
- func (c *OIDCClient) SupportedPKCEMethods() []string
- type Option
- type Token
- type Transport
Constants ¶
const DefaultLocalServerSuccessHTML = `` /* 477-byte string literal not displayed */
DefaultLocalServerSuccessHTML is a default response body on authorization success.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AuthCodeFlowOpts ¶
type AuthCodeFlowOpts struct {
OAuth2Config oauth2.Config
// Hostname of the redirect URL.
// You can set this if your provider does not accept localhost.
// Default to localhost.
RedirectURLHostname string
// Options for an authorization request.
// You can set oauth2.AccessTypeOffline and the PKCE options here.
AuthCodeOptions []oauth2.AuthCodeOption
// Options for a token request.
// You can set the PKCE options here.
TokenRequestOptions []oauth2.AuthCodeOption
// State parameter in the authorization request.
// Default to a string of random 32 bytes.
State string
// Candidates of hostname and port which the local server binds to.
// You can set port number to 0 to allocate a free port.
// If multiple addresses are given, it will try the ports in order.
// If nil or an empty slice is given, it defaults to "127.0.0.1:0" i.e. a free port.
LocalServerBindAddress []string
// Response HTML body on authorization completed.
// Default to DefaultLocalServerSuccessHTML.
LocalServerSuccessHTML string
// Middleware for the local server. Default to none.
LocalServerMiddleware func(h http.Handler) http.Handler
// A channel to send its URL when the local server is ready. Default to none.
LocalServerReadyChan chan<- string
// Redirect URL upon successful login
SuccessRedirectURL string
// Redirect URL upon failed login
FailureRedirectURL string
Logf func(string, ...any)
}
type Client ¶
type Client interface {
ClientSecret() string
SetClientSecret(s string)
SupportedPKCEMethods() []string
GetTokenByAuthCode(
ctx context.Context,
opts GetTokenByAuthCodeOpts,
localServerReadyChan chan<- string,
) (*Token, error)
GetTokenByPassword(ctx context.Context, username string, password string) (*Token, error)
DeviceAuth(ctx context.Context) (*oauth2.DeviceAuthResponse, error)
GetTokenByDeviceCode(ctx context.Context, resp *oauth2.DeviceAuthResponse) (*Token, error)
GetTokenByDeviceCodeManual(ctx context.Context, resp *oauth2.DeviceAuthResponse) (*Token, error)
GetTokenByClientCredentials(ctx context.Context) (*Token, error)
Refresh(ctx context.Context, refreshToken string) (*Token, error)
}
type GetTokenByAuthCodeOpts ¶
type Listener ¶
type Listener struct {
// URL to the listener.
// This is always "http://localhost:PORT" regardless of the listening address.
URL *url.URL
// contains filtered or unexported fields
}
Listener wraps a net.Listener and provides its URL.
func NewListener ¶
NewListener starts a Listener on one of the addresses. Caller should close the listener finally.
If nil or an empty slice is given, it defaults to "127.0.0.1:0". If multiple address are given, it will try the addresses in order.
If the port in the address is 0, it will allocate a free port.
If no port is available, it will return an NoAvailablePortError.
func NewListenerOn ¶
NewListenerOn starts a Listener on the address. Caller should close the listener finally.
If an empty string is given, it defaults to "127.0.0.1:0".
If the port in the address is 0, it will allocate a free port.
type NoAvailablePortError ¶
type NoAvailablePortError interface {
error
// Return the array of errors.
// You can unwrap the error to check the root cause.
Causes() []error
}
NoAvailablePortError provides a set of errors on the port allocation.
type OIDCClient ¶
type OIDCClient struct {
// contains filtered or unexported fields
}
func (*OIDCClient) ClientSecret ¶
func (c *OIDCClient) ClientSecret() string
func (*OIDCClient) DeviceAuth ¶
func (c *OIDCClient) DeviceAuth(ctx context.Context) (*oauth2.DeviceAuthResponse, error)
DeviceAuth initializes the device authorization code challenge
func (*OIDCClient) GetTokenByAuthCode ¶
func (c *OIDCClient) GetTokenByAuthCode( ctx context.Context, ops GetTokenByAuthCodeOpts, localServerReadyChan chan<- string, ) (*Token, error)
GetTokenByAuthCode performs the authentication code flow
func (*OIDCClient) GetTokenByClientCredentials ¶
func (c *OIDCClient) GetTokenByClientCredentials(ctx context.Context) (*Token, error)
GetTokenByClientCredentials performs the client credentials token flow.
func (*OIDCClient) GetTokenByDeviceCode ¶
func (c *OIDCClient) GetTokenByDeviceCode(ctx context.Context, resp *oauth2.DeviceAuthResponse) (*Token, error)
GetTokenByDeviceCode exchanges the device code to a token
func (*OIDCClient) GetTokenByDeviceCodeManual ¶
func (c *OIDCClient) GetTokenByDeviceCodeManual(ctx context.Context, resp *oauth2.DeviceAuthResponse) (*Token, error)
GetTokenByDeviceCodeManual manually exchanges the device code to a token
func (*OIDCClient) GetTokenByPassword ¶
func (c *OIDCClient) GetTokenByPassword(ctx context.Context, username string, password string) (*Token, error)
GetTokenByPassword performs the resource owner password credentials flow
func (*OIDCClient) SetClientSecret ¶
func (c *OIDCClient) SetClientSecret(s string)
func (*OIDCClient) SupportedPKCEMethods ¶
func (c *OIDCClient) SupportedPKCEMethods() []string
SupportedPKCEMethods returns the PKCE methods supported by the provider. This may return nil if PKCE is not supported.