Documentation
¶
Index ¶
- Constants
- Variables
- func ClearAuthProviderVerifyCookie(w http.ResponseWriter)
- func ClearSetupLoginCookie(w http.ResponseWriter, secure bool)
- func ContextWithProviderGroupIDPrefix(ctx context.Context, prefix string) context.Context
- func ContextWithProviderURL(ctx context.Context, url string) context.Context
- func HasSetupLoginCookie(r *http.Request, secure bool) bool
- func OriginOf(rawURL string) string
- func ProviderGroupIDPrefixFromContext(ctx context.Context) string
- func ProviderURLFromContext(ctx context.Context) string
- func SafeRedirectPath(rd string) string
- func SetSetupLoginCookie(w http.ResponseWriter, id string, secure bool)
- func SetupLoginCookieName(secure bool) string
- func TrustOrigins(protection *http.CrossOriginProtection, trustedURLs ...string)
- func TrustedOrigins(trustedURLs ...string) []string
- func ValidateGroupID(groupID, prefix string) error
- func ValidateGroupIDPrefix(prefix string) error
- type GroupInfo
- type SerializableRequest
- type SerializableState
Constants ¶
const ( ObotAccessTokenCookie = "obot_access_token" // ObotBootstrapCookie carries the bootstrap token of a browser that logged in with it. ObotBootstrapCookie = "obot-bootstrap" // AuthProviderVerifyCookie carries the ID of an in-flight staged-provider verification across // the OAuth round trip, so only the browser that started it can log in through the staged // provider. AuthProviderVerifyCookie = "obot_auth_provider_verify" // AuthProviderVerifyWindow is how long a staged-provider verification stays open. AuthProviderVerifyWindow = 15 * time.Minute // SetupLoginWindow is how long the setup login cookie lasts. The cookie is only needed for the redirects that // immediately follow the OAuth round trip, so it is short. SetupLoginWindow = 5 * time.Minute )
const ( // HeaderObotAPIKey carries an Obot API key alongside another credential, on LLM proxy requests. It is // authenticated only there. HeaderObotAPIKey = "X-Obot-Api-Key" )
Variables ¶
var ( // CredentialHeaders are the request headers from which Obot's authenticators read a credential, such as a bearer // token or an API key, that a client sets itself. They do not include the headers of upstream credentials, such as // an LLM provider's API key, that Obot forwards or strips but never authenticates. CredentialHeaders = []string{"Authorization", "X-API-Key", HeaderObotAPIKey} )
Functions ¶
func ClearAuthProviderVerifyCookie ¶ added in v0.26.1
func ClearAuthProviderVerifyCookie(w http.ResponseWriter)
func ClearSetupLoginCookie ¶ added in v0.28.2
func ClearSetupLoginCookie(w http.ResponseWriter, secure bool)
ClearSetupLoginCookie removes the setup login cookie once the setup login it marks has finished.
func ContextWithProviderGroupIDPrefix ¶ added in v0.25.2
ContextWithProviderGroupIDPrefix adds the auth provider's declared group ID prefix to the context.
func ContextWithProviderURL ¶
ContextWithProviderURL adds the auth provider URL to the context
func HasSetupLoginCookie ¶ added in v0.28.2
HasSetupLoginCookie reports whether r comes from a browser that just finished a setup login. A cookie that was cleared but that the browser still sends is empty, and does not count.
func OriginOf ¶ added in v0.28.2
OriginOf returns the scheme://host origin of rawURL, such as a Referer, or "" if it has no scheme and host.
The origin is in the canonical form that browsers send in Origin and Referer: a lowercase host, without the scheme's default port. Trusted origins are compared with what a browser sends as exact strings, both here and in http.CrossOriginProtection, so a configured URL such as https://Obot.Example.com:443 would otherwise never match.
func ProviderGroupIDPrefixFromContext ¶ added in v0.25.2
ProviderGroupIDPrefixFromContext retrieves the auth provider's declared group ID prefix.
func ProviderURLFromContext ¶
ProviderURLFromContext retrieves the auth provider URL from the context
func SafeRedirectPath ¶ added in v0.26.0
SafeRedirectPath sanitizes a caller-supplied redirect so that it can only point back into Obot, returning "/" for anything else. Browsers treat "\" as "/" when resolving against an http(s) base, so "/\evil.com" is another spelling of "//evil.com" and must be rejected too. Browsers also strip tabs and newlines from URLs, so "/\t/evil.com" is rejected along with any other control character.
func SetSetupLoginCookie ¶ added in v0.28.2
func SetSetupLoginCookie(w http.ResponseWriter, id string, secure bool)
SetSetupLoginCookie marks this browser as having just finished the setup login for the token request id.
func SetupLoginCookieName ¶ added in v0.28.2
SetupLoginCookieName returns the name of the cookie that marks a finished setup login. secure is whether Obot's server URL is https.
Over https the name carries the __Host- prefix, so a same-site host cannot plant the cookie. Browsers reject a __Host- cookie that is not Secure, so over plain http the name has no prefix and the cookie has no such protection. Neither name is ever accepted in place of the other: accepting the unprefixed name over https would let a planted cookie through again.
func TrustOrigins ¶ added in v0.28.2
func TrustOrigins(protection *http.CrossOriginProtection, trustedURLs ...string)
TrustOrigins adds the origins of Obot's own URLs to protection, so that requests from them are not refused as cross-origin. A URL without a scheme and host is skipped with a warning.
func TrustedOrigins ¶ added in v0.28.2
TrustedOrigins returns the origins of Obot's own URLs, in the scheme://host form that browsers send in Origin. A URL without a scheme and host is skipped with a warning, so the result never contains an empty origin.
func ValidateGroupID ¶ added in v0.25.2
ValidateGroupID checks that a group returned by an auth provider belongs to the namespace that provider declared in its manifest.
func ValidateGroupIDPrefix ¶ added in v0.25.2
ValidateGroupIDPrefix validates a provider-declared group ID namespace. An empty prefix means that the provider does not support groups.
Types ¶
type GroupInfo ¶
type GroupInfo struct {
ID string `json:"id"`
Name string `json:"name"`
IconURL *string `json:"iconURL"`
}
GroupInfo represents information about a user group from an authentication provider
type SerializableRequest ¶ added in v0.10.0
type SerializableRequest struct {
Method string `json:"method"`
URL string `json:"url"`
Header map[string][]string `json:"header"`
}
SerializableRequest represents an HTTP request that can be serialized for authentication flows
type SerializableState ¶ added in v0.10.0
type SerializableState struct {
ExpiresOn *time.Time `json:"expiresOn"`
AccessToken string `json:"accessToken"`
PreferredUsername string `json:"preferredUsername"`
User string `json:"user"`
Email string `json:"email"`
SetCookies []string `json:"setCookies"`
RequirePasswordChange bool `json:"requirePasswordChange,omitempty"`
}
SerializableState represents the authentication state returned from auth providers