Documentation
¶
Overview ¶
Package oauthimplements the OAuth 2.0 Device Authorization Grant (RFC 8628) for authenticating with Sourcegraph instances.
Index ¶
Constants ¶
View Source
const ( // DefaultClientID is a predefined Client ID built into Sourcegraph DefaultClientID = "sgo_cid_sourcegraph-cli" GrantTypeDeviceCode string = "urn:ietf:params:oauth:grant-type:device_code" ScopeOpenID string = "openid" ScopeProfile string = "profile" ScopeEmail string = "email" ScopeOfflineAccess string = "offline_access" ScopeUserAll string = "user:all" )
Variables ¶
This section is empty.
Functions ¶
func IsOAuthTransport ¶
func IsOAuthTransport(trp http.RoundTripper) bool
IsOAuthTransport checks wether the underlying type of the given RoundTripper is a OAuthTransport
Types ¶
type Client ¶
type Client interface {
ClientID() string
Discover(ctx context.Context, endpoint string) (*OIDCConfiguration, error)
Start(ctx context.Context, endpoint string, scopes []string) (*DeviceAuthResponse, error)
Poll(ctx context.Context, endpoint, deviceCode string, interval time.Duration, expiresIn int) (*TokenResponse, error)
Refresh(ctx context.Context, token *Token) (*TokenResponse, error)
}
type DeviceAuthResponse ¶
type ErrorResponse ¶
type OIDCConfiguration ¶
type OIDCConfiguration struct {
Issuer string `json:"issuer,omitempty"`
TokenEndpoint string `json:"token_endpoint,omitempty"`
DeviceAuthorizationEndpoint string `json:"device_authorization_endpoint,omitempty"`
}
OIDCConfiguration represents the relevant fields from the OpenID Connect Discovery document at /.well-known/openid-configuration
type Token ¶
type Token struct {
Endpoint string `json:"endpoint"`
ClientID string `json:"client_id,omitempty"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresAt time.Time `json:"expires_at"`
}
func (*Token) HasExpired ¶
type TokenResponse ¶
type TokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresIn int `json:"expires_in,omitempty"`
TokenType string `json:"token_type"`
Scope string `json:"scope,omitempty"`
}
func (*TokenResponse) Token ¶
func (t *TokenResponse) Token(endpoint string) *Token
Click to show internal directories.
Click to hide internal directories.