Documentation
¶
Overview ¶
Package oauthimplements the OAuth 2.0 Device Authorization Grant (RFC 8628) for authenticating with Sourcegraph instances.
Index ¶
Constants ¶
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, endpointURL *url.URL) (*OIDCConfiguration, error)
Start(ctx context.Context, endpointURL *url.URL, scopes []string) (*DeviceAuthResponse, error)
Poll(ctx context.Context, endpointURL *url.URL, 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 TokenRefresher ¶
type TokenRefresher struct {
// contains filtered or unexported fields
}
func NewTokenRefresher ¶
func NewTokenRefresher(token *Token) *TokenRefresher
func (*TokenRefresher) GetToken ¶
func (r *TokenRefresher) GetToken(ctx context.Context) (Token, error)
GetToken returns a value copy of the token. If the token has expired or expiring soon it will be refreshed before returning. Once the token is refreshed, the in-memory token is updated and a best effort is made to store the token.
If storing the token fails, no error is returned. An error is only returned if refreshing the token fails.
type TokenResponse ¶
type Transport ¶
type Transport struct {
Base http.RoundTripper
// contains filtered or unexported fields
}
func NewTransport ¶
func NewTransport(base http.RoundTripper, token *Token) *Transport