Documentation
¶
Overview ¶
Package oauth implements the client side of the Webda OAuth 2.1 authorization server.
Index ¶
- Variables
- func AuthorizeURL(m *Metadata, p AuthorizeParams) string
- func Origin(raw string) string
- func RandomState() (string, error)
- func Revoke(ctx context.Context, hc *http.Client, m *Metadata, clientID, token string) error
- func Sanitize(s string) string
- func Sleep(ctx context.Context, d time.Duration) error
- type AuthorizeParams
- type DeviceCode
- type Error
- type Loopback
- type Metadata
- type PKCE
- type Tokens
Constants ¶
This section is empty.
Variables ¶
var ErrNotSupported = errors.New("this server does not support OAuth sign-in")
ErrNotSupported is returned when the server exposes no OAuth discovery document.
Functions ¶
func AuthorizeURL ¶
func AuthorizeURL(m *Metadata, p AuthorizeParams) string
AuthorizeURL builds the browser authorization URL.
func Origin ¶
Origin returns scheme://host:port of an absolute URL, with the default port made explicit ("" when raw is not an absolute URL with a host).
func RandomState ¶
RandomState returns a 16 random bytes base64url state.
Types ¶
type AuthorizeParams ¶
type AuthorizeParams struct{ ClientID, RedirectURI, State, Challenge, Scope, Hostname, Prompt string }
AuthorizeParams are the inputs of the authorization request.
type DeviceCode ¶
type DeviceCode struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
VerificationURIComplete string `json:"verification_uri_complete"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
}
DeviceCode is a device authorization answer (RFC 8628).
func StartDevice ¶
func StartDevice(ctx context.Context, hc *http.Client, m *Metadata, clientID, scope, hostname string) (*DeviceCode, error)
StartDevice requests a device and user code.
type Loopback ¶
type Loopback struct {
RedirectURI string // http://127.0.0.1:<port>/callback
// contains filtered or unexported fields
}
Loopback is a one-shot authorization callback listener on 127.0.0.1 (RFC 8252).
func ListenLoopback ¶
ListenLoopback binds 127.0.0.1:0 and serves GET /callback.
func (*Loopback) Arm ¶
Arm sets the expected state and the result page before the browser is opened, so a callback that arrives immediately (remembered consent) is accepted. Callbacks before Arm are refused.
type Metadata ¶
type Metadata struct {
Issuer string `json:"issuer"`
AuthorizationEndpoint string `json:"authorization_endpoint"`
TokenEndpoint string `json:"token_endpoint"`
RevocationEndpoint string `json:"revocation_endpoint"`
DeviceAuthorizationEndpoint string `json:"device_authorization_endpoint"`
ResultURI string `json:"webda_result_uri"`
OperationsURI string `json:"webda_operations_uri"`
}
Metadata is the authorization server discovery document.
type PKCE ¶
type PKCE struct{ Verifier, Challenge string }
PKCE holds a code verifier and its S256 challenge.
type Tokens ¶
type Tokens struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresIn int `json:"expires_in"`
Scope string `json:"scope"`
}
Tokens is a token endpoint answer.
func ExchangeCode ¶
func ExchangeCode(ctx context.Context, hc *http.Client, m *Metadata, clientID, code, verifier, redirectURI string) (*Tokens, error)
ExchangeCode trades an authorization code for tokens.
func PollDevice ¶
func PollDevice(ctx context.Context, hc *http.Client, m *Metadata, clientID string, dc *DeviceCode, sleep func(context.Context, time.Duration) error) (*Tokens, error)
PollDevice polls the token endpoint until tokens, a terminal error, ctx done or expiry.