Documentation
¶
Index ¶
- func IsGithubDotComURL(str string) bool
- func IsInvalidTokenError(err error) bool
- type AppInstallation
- type Config
- func (c *Config) AppInstallations(ctx context.Context, token string) ([]codersdk.ExternalAuthAppInstallation, bool, error)
- func (c *Config) GenerateTokenExtra(token *oauth2.Token) (pqtype.NullRawMessage, error)
- func (c *Config) Git() (gitprovider.Provider, error)
- func (c *Config) RefreshToken(ctx context.Context, db database.Store, ...) (database.ExternalAuthLink, error)
- func (c *Config) RevokeToken(ctx context.Context, link database.ExternalAuthLink) (bool, error)
- func (c *Config) TokenRevocationRequest(ctx context.Context, link database.ExternalAuthLink) (*http.Request, error)
- func (c *Config) TokenRevocationRequestGitHub(ctx context.Context, link database.ExternalAuthLink) (*http.Request, error)
- func (c *Config) TokenRevocationRequestRFC7009(ctx context.Context, link database.ExternalAuthLink) (*http.Request, error)
- func (c *Config) TokenRevocationResponseOk(res *http.Response) bool
- func (c *Config) ValidateToken(ctx context.Context, token *oauth2.Token) (bool, *codersdk.ExternalAuthUser, error)
- type DeviceAuth
- type ExchangeDeviceCodeResponse
- type InvalidTokenError
- type SingleflightGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsGithubDotComURL ¶ added in v2.14.0
IsGithubDotComURL returns true if the given URL is a github.com URL.
func IsInvalidTokenError ¶ added in v2.13.0
Types ¶
type AppInstallation ¶
type Config ¶
type Config struct {
promoauth.InstrumentedOAuth2Config
// Logs rate-limited validation warnings. Zero value discards output.
Logger slog.Logger
// ID is a unique identifier for the authenticator.
ID string
// Type is the type of provider.
Type string
ClientID string
ClientSecret string
// DeviceAuth is set if the provider uses the device flow.
DeviceAuth *DeviceAuth
// DisplayName is the name of the provider to display to the user.
DisplayName string
// DisplayIcon is the path to an image that will be displayed to the user.
DisplayIcon string
// ExtraTokenKeys is a list of extra properties to
// store in the database returned from the token endpoint.
//
// e.g. Slack returns `authed_user` in the token which is
// a payload that contains information about the authenticated
// user.
ExtraTokenKeys []string
// NoRefresh stops Coder from using the refresh token
// to renew the access token.
//
// Some organizations have security policies that require
// re-authentication for every token.
NoRefresh bool
// ValidateURL ensures an access token is valid before
// returning it to the user. If omitted, tokens will
// not be validated before being returned.
ValidateURL string
RevokeURL string
RevokeTimeout time.Duration
// Regex is a Regexp matched against URLs for
// a Git clone. e.g. "Username for 'https://github.com':"
// The regex would be `github\.com`..
Regex *regexp.Regexp
// APIBaseURL is the base URL for provider REST API calls
// (e.g., "https://api.github.com" for GitHub). Derived from
// defaults when not explicitly configured.
APIBaseURL string
// If nil, http.DefaultClient is used. The value is read once at
// the first successful Git() call; later assignments have no
// effect because the provider is memoized.
HTTPClient *http.Client
// AppInstallURL is for GitHub App's (and hopefully others eventually)
// to provide a link to install the app. There's installation
// of the application, and user authentication. It's possible
// for the user to authenticate but the application to not.
AppInstallURL string
// AppInstallationsURL is an API endpoint that returns a list of
// installations for the user. This is used for GitHub Apps.
AppInstallationsURL string
// Deprecated: Injected MCP in AI Bridge is deprecated and will be removed in a future release.
//
// MCPURL is the endpoint that clients must use to communicate with the associated
// MCP server.
MCPURL string
// Deprecated: Injected MCP in AI Bridge is deprecated and will be removed in a future release.
//
// MCPToolAllowRegex is a [regexp.Regexp] to match tools which are explicitly allowed to be
// injected into Coder AI Bridge upstream requests.
// In the case of conflicts, [MCPToolDenylistPattern] overrides items evaluated by this list.
// This field can be nil if unspecified in the config.
MCPToolAllowRegex *regexp.Regexp
// Deprecated: Injected MCP in AI Bridge is deprecated and will be removed in a future release.
//
// MCPToolDenyRegex is a [regexp.Regexp] to match tools which are explicitly NOT allowed to be
// injected into Coder AI Bridge upstream requests.
// In the case of conflicts, items evaluated by this list override [MCPToolAllowRegex].
// This field can be nil if unspecified in the config.
MCPToolDenyRegex *regexp.Regexp
CodeChallengeMethodsSupported []promoauth.Oauth2PKCEChallengeMethod
// RefreshRetryInitialBackoff overrides the initial wait between transient
// refresh retry attempts. A zero value applies
// defaultRefreshRetryInitialBackoff.
RefreshRetryInitialBackoff time.Duration
// RefreshRetryMaxBackoff overrides the maximum wait between transient
// refresh retry attempts. A zero value applies
// defaultRefreshRetryMaxBackoff.
RefreshRetryMaxBackoff time.Duration
// RefreshRetryTimeout overrides the total budget for retrying a transient
// refresh failure across all attempts. A zero value applies
// defaultRefreshRetryTimeout. A negative value disables transient-failure
// retries entirely, so exactly one refresh attempt is made.
RefreshRetryTimeout time.Duration
// RefreshGroup deduplicates concurrent requests.
RefreshGroup SingleflightGroup
// RefreshLeaseInitialBackoff is the starting wait between polls to check
// whether another replica has finished refreshing.
RefreshLeaseInitialBackoff time.Duration
// RefreshLeaseMaxBackoff is the maximum wait between polls to check whether
// another replica has finished refreshing.
RefreshLeaseMaxBackoff time.Duration
// contains filtered or unexported fields
}
Config is used for authentication for Git operations.
func ConvertConfig ¶
func ConvertConfig(ctx context.Context, logger slog.Logger, instrument *promoauth.Factory, entries []codersdk.ExternalAuthConfig, accessURL *url.URL, httpClient *http.Client) ([]*Config, error)
ConvertConfig converts the SDK configuration entry format to the parsed and ready-to-consume in coderd provider type. If httpClient is nil, http.DefaultClient is used.
func (*Config) AppInstallations ¶
func (c *Config) AppInstallations(ctx context.Context, token string) ([]codersdk.ExternalAuthAppInstallation, bool, error)
AppInstallations returns a list of app installations for the given token. If the provider does not support app installations, it returns nil.
func (*Config) GenerateTokenExtra ¶ added in v2.3.0
GenerateTokenExtra generates the extra token data to store in the database.
func (*Config) Git ¶ added in v2.32.0
func (c *Config) Git() (gitprovider.Provider, error)
Git returns a Provider for this config. It returns (nil, nil) when this config's type has no provider implementation, which covers both non-git types (e.g. Slack, JFrog) and git types that are not implemented yet (bitbucket-*, azure-devops*, gitea). Callers cannot distinguish the two cases from the return values. Returns a non-nil error if provider construction fails.
The provider is built on the first successful call and cached for the lifetime of the Config, so its in-memory response cache survives across calls. The provider uses c.HTTPClient for API requests; if c.HTTPClient is nil, http.DefaultClient is used.
func (*Config) RefreshToken ¶
func (c *Config) RefreshToken(ctx context.Context, db database.Store, externalAuthLink database.ExternalAuthLink) (database.ExternalAuthLink, error)
RefreshToken automatically refreshes the token if expired and permitted. Tokens are then validated, whether or not they were refreshed.
func (*Config) RevokeToken ¶ added in v2.27.0
func (*Config) TokenRevocationRequest ¶ added in v2.27.0
func (*Config) TokenRevocationRequestGitHub ¶ added in v2.27.0
func (*Config) TokenRevocationRequestRFC7009 ¶ added in v2.27.0
func (*Config) TokenRevocationResponseOk ¶ added in v2.27.0
func (*Config) ValidateToken ¶
func (c *Config) ValidateToken(ctx context.Context, token *oauth2.Token) (bool, *codersdk.ExternalAuthUser, error)
ValidateToken checks if the Git token provided is valid. The user is optionally returned if the provider supports it. Returns valid=true when: the provider confirmed the token, no ValidateURL is configured, or the validation endpoint returned a rate-limited response (403 with rate-limit headers or 429).
type DeviceAuth ¶
type DeviceAuth struct {
// Config is provided for the http client method.
Config promoauth.InstrumentedOAuth2Config
ClientID string
TokenURL string
Scopes []string
CodeURL string
}
func (*DeviceAuth) AuthorizeDevice ¶
func (c *DeviceAuth) AuthorizeDevice(ctx context.Context) (*codersdk.ExternalAuthDevice, error)
AuthorizeDevice begins the device authorization flow. See: https://tools.ietf.org/html/rfc8628#section-3.1
func (*DeviceAuth) ExchangeDeviceCode ¶
func (c *DeviceAuth) ExchangeDeviceCode(ctx context.Context, deviceCode string) (*oauth2.Token, error)
ExchangeDeviceCode exchanges a device code for an access token. The boolean returned indicates whether the device code is still pending and the caller should try again.
type InvalidTokenError ¶ added in v2.13.0
type InvalidTokenError string
InvalidTokenError is a case where the "RefreshToken" failed to complete as a result of invalid credentials. Error contains the reason of the failure.
func (InvalidTokenError) Error ¶ added in v2.13.0
func (e InvalidTokenError) Error() string
type SingleflightGroup ¶ added in v2.36.0
type SingleflightGroup interface {
DoChan(key string, fn func() (any, error)) <-chan singleflight.Result
}
SingleflightGroup exposes a subset of singleflight.Group for easier testing. singleflight.Group should be used instead of implementing this in production.