Documentation
¶
Index ¶
- Constants
- Variables
- func IsNonInteractive(ctx context.Context) bool
- func NonInteractive(ctx context.Context) context.Context
- type Handler
- type OidcConfig
- type OidcHandler
- func (h *OidcHandler) Callback(w http.ResponseWriter, r *http.Request)
- func (h *OidcHandler) GetTokens() (*Tokens, error)
- func (h *OidcHandler) GetTokensContext(ctx context.Context) (*Tokens, error)
- func (h *OidcHandler) HttpHandler() http.Handler
- func (h *OidcHandler) Login(w http.ResponseWriter, r *http.Request)
- type OidcHandlerOption
- type Tokens
Constants ¶
const ( // DefaultLoginTimeout is how long GetTokensContext waits for the interactive // login flow to complete DefaultLoginTimeout = time.Minute * 5 )
Variables ¶
var ( ErrLoginFailed = errors.New("interactive login failed") // ErrInteractiveLoginRequired is returned by GetTokensContext when called // with a [NonInteractive] context and no cached or refreshed tokens are // available ErrInteractiveLoginRequired = errors.New("interactive login required") )
Functions ¶
func IsNonInteractive ¶
IsNonInteractive reports whether ctx (or a parent) was created by NonInteractive. Handler implementations must not start an interactive login when this is true.
func NonInteractive ¶
NonInteractive returns a copy of ctx that prevents GetTokensContext from starting an interactive login. Only cached tokens or a refresh token are used, otherwise ErrInteractiveLoginRequired is returned. This is intended for background renewals that must not open a browser.
Types ¶
type Handler ¶
type Handler interface {
GetTokens() (*Tokens, error)
GetTokensContext(ctx context.Context) (*Tokens, error)
}
Handler provides the tokens needed to request a certificate. Any interactive login, including running the local HTTP server it needs, is handled by the implementation, which must not start one when IsNonInteractive reports true for the provided context.
type OidcConfig ¶
type OidcHandler ¶
type OidcHandler struct {
// contains filtered or unexported fields
}
func NewOidcHandler ¶
func NewOidcHandler(config OidcConfig, opts ...OidcHandlerOption) (*OidcHandler, error)
NewOidcHandler creates a handler for the OIDC provider at config.Issuer.
The IdP is not contacted until tokens are first needed, so the handler can be created while the IdP is unreachable (such as before the network is up). Provider discovery is then performed by GetTokensContext, and retried by later calls until it succeeds. Each request to the IdP is limited to 30 seconds.
func (*OidcHandler) Callback ¶
func (h *OidcHandler) Callback(w http.ResponseWriter, r *http.Request)
The Callback method is intended for use as the handler function for the callback URL of the OIDC auth flow process as part of the Serverless SSH CA
The result of the callback, whether successful or not, is passed to the waiting GetTokensContext call. Callbacks received when no interactive login is in progress are rejected.
func (*OidcHandler) GetTokens ¶
func (h *OidcHandler) GetTokens() (*Tokens, error)
func (*OidcHandler) GetTokensContext ¶
func (h *OidcHandler) GetTokensContext(ctx context.Context) (*Tokens, error)
GetTokensContext returns access and ID tokens. Previously obtained tokens are reused until shortly before they expire, then a refresh token is used if one is available. Otherwise the interactive login flow is started: a local HTTP server is run on the redirect URL address and this blocks until the Callback completes, the login timeout is reached or ctx is done.
If ctx was created by NonInteractive no interactive login is started and ErrInteractiveLoginRequired is returned instead.
func (*OidcHandler) HttpHandler ¶
func (h *OidcHandler) HttpHandler() http.Handler
HttpHandler returns the http.Handler for the login and callback paths. GetTokensContext serves this itself when an interactive login is needed.
func (*OidcHandler) Login ¶
func (h *OidcHandler) Login(w http.ResponseWriter, r *http.Request)
The Login method is intended for use as the handler function for the initial login URL of the OIDC auth flow process.
This will start the OIDC auth flow process and redirect the user to the configured OIDC IdP.
type OidcHandlerOption ¶
type OidcHandlerOption func(*OidcHandler)
func WithLogger ¶
func WithLogger(logger *slog.Logger) OidcHandlerOption
WithLogger sets the logger used by the handler. The default discards all log messages. A nil logger is ignored.
func WithLoginTimeout ¶
func WithLoginTimeout(d time.Duration) OidcHandlerOption
WithLoginTimeout sets how long GetTokensContext waits for the interactive login flow to complete. The default is DefaultLoginTimeout.
func WithTokenStore ¶
func WithTokenStore(store tokenstore.Store) OidcHandlerOption
WithTokenStore sets the store used to persist the refresh token between runs. The default is a tokenstore.DiscardStore, which does not persist the refresh token.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package tokenstore persists the OIDC refresh token between runs so a new certificate can be requested without an interactive login.
|
Package tokenstore persists the OIDC refresh token between runs so a new certificate can be requested without an interactive login. |