Documentation
¶
Index ¶
Constants ¶
View Source
const ( // ProviderTypeOAuth2 represents an OAuth2 account type. ProviderTypeOAuth2 = "oauth2" // ProviderTypeOIDC represents an OIDC account type. ProviderTypeOIDC = "oidc" // ProviderTypeSAML represents a SAML account type. ProviderTypeSAML = "saml" // ProviderTypeEmail represents an email account type. ProviderTypeEmail = "email" // ProviderTypeWebAuthn represents a WebAuthn account type. ProviderTypeWebAuthn = "webauthn" // ProviderTypeUnknown represents an unknown account type. ProviderTypeUnknown = "unknown" )
View Source
const NoopEmail = ""
NoopEmail is the email address used when no email is available.
Variables ¶
View Source
var ( // ErrOidcNoVerifiedPrimaryEmail is returned when no verified primary email is found. ErrOidcNoVerifiedPrimaryEmail = errors.New("no verified primary email found") // ErrOidcFailedFetchUser is returned when the user fails to be fetched. ErrOidcFailedFetchUser = errors.New("no failed to fetch user") // ErrOidcNotAllowedOrg is returned when the user is not in the allowed organization. ErrOidcNotAllowedOrg = errors.New("user not in allowed org") // ErrOidcNoName is returned when the user has no display name set. ErrOidcNoName = errors.New("user has no display name set") // ErrOidcMissingIDToken is returned when no ID token is found. ErrOidcMissingIDToken = errors.New("no id token found") )
View Source
var DefaultClient = &http.Client{ Transport: &http.Transport{ MaxIdleConnsPerHost: 20, }, Timeout: 10 * time.Second, }
DefaultClient is the default HTTP client used. TODO: allows to configure the client via options.
View Source
var DefaultScopes = []string{"openid", "email", "offline_access"}
DefaultScopes holds the default scopes used for GitHub.
Functions ¶
Types ¶
type Claims ¶
type Claims struct {
// Name is the user's name.
Name string `json:"name"`
// Email is the user's email address.
Email string `json:"email"`
// Verified indicates whether the user's email address has been verified.
Verified bool `json:"email_verified"`
// Groups is the list of groups the user belongs to.
Groups []string `json:"groups"`
}
Claims holds the claims from the ID token.
type DeviceAuth ¶
type DeviceAuth struct {
// DeviceCode is the device code used to authenticate the device.
DeviceCode string `json:"device_code"`
// UserCode is the user code used to authenticate the device.
UserCode string `json:"user_code"`
// VerificationURI is the URI to verify the device code.
VerificationURI string `json:"verification_uri"`
// VerificationURIComplete is the URI to verify the device code with the client secret.
VerificationURIComplete string `json:"verification_uri_complete"`
// ExpiresIn is the number of seconds until the device code expires.
ExpiresIn time.Time `json:"expires_in"`
// Interval is the number of seconds between polling requests for device code status.
Interval int64 `json:"interval"`
}
DeviceAuth is a struct that holds the device authentication response data.
type OidcProvider ¶
type OidcProvider interface {
// Begin is a method that begins the device authentication process.
Begin(ctx context.Context) (*DeviceAuth, error)
// Finish is a method that finishes the device authentication process.
// TODO: could be returned in a token structure
Finish(ctx context.Context, deviceAuth *DeviceAuth) (*Token, error)
// Refresh is a method that refreshes the device authentication token.
Refresh(ctx context.Context, token *Token) error
}
OidcProvider is an interface that defines the methods for an OIDC provider.
type Opt ¶
type Opt func(*oidcProvider)
Opt is a function that configures the GitHub provider.
func WithScopes ¶
WithScopes sets the scopes for the GitHub provider.
type Token ¶
type Token struct {
// ProviderType is the type of provider that issued the token.
ProviderType string `json:"provider_type"`
// AccessToken is the token that authorizes and authenticates
// the requests.
AccessToken string `json:"access_token"`
// TokenType is the type of token.
// The Type method returns either this or "Bearer", the default.
TokenType string `json:"token_type,omitempty"`
// RefreshToken is a token that's used by the application
// (as opposed to the user) to refresh the access token
// if it expires.
RefreshToken string `json:"refresh_token,omitempty"`
// Expiry is the optional expiration time of the access token.
//
// If zero, [TokenSource] implementations will reuse the same
// token forever and RefreshToken or equivalent
// mechanisms for that TokenSource will not be used.
Expiry time.Time `json:"expiry,omitempty"`
// ExpiresIn is the OAuth2 wire format "expires_in" field,
// which specifies how many seconds later the token expires,
// relative to an unknown time base approximately around "now".
// It is the application's responsibility to populate
// `Expiry` from `ExpiresIn` when required.
ExpiresIn int64 `json:"expires_in,omitempty"`
// IDToken is the raw ID token returned from the provider.
IDToken string `json:"id_token,omitempty"`
// Claims is the parsed claims from the ID token.
Claims *Claims `json:"claims,omitempty"`
}
Token is an alias for oauth2.Token.
Click to show internal directories.
Click to hide internal directories.