Documentation ¶
Overview ¶
Package oauth implements some helper wrappers ontop of the existing google implementation of oauth.
Index ¶
- Variables
- func SerializeState(state State) (output string, err error)
- type Any
- type Config
- func (c Config) GetClientID(inherited ...string) string
- func (c Config) GetClientSecret(inherited ...string) string
- func (c Config) GetHostedDomain(inherited ...string) string
- func (c Config) GetRedirectURI(inherited ...string) string
- func (c Config) GetScopes(inherited ...[]string) []string
- func (c Config) GetSecret(defaults ...[]byte) ([]byte, error)
- func (c Config) IsZero() bool
- type Error
- type Labels
- type Manager
- func (m *Manager) ClientID() string
- func (m *Manager) ClientSecret() string
- func (m *Manager) CreateState(redirect ...string) (state State)
- func (m *Manager) FetchProfile(ctx context.Context, accessToken string) (profile Profile, err error)
- func (m *Manager) Finish(r *http.Request) (result *Result, err error)
- func (m *Manager) HostedDomain() string
- func (m *Manager) OAuthURL(r *http.Request, redirect ...string) (oauthURL string, err error)
- func (m *Manager) RedirectURI() string
- func (m *Manager) RequestCreator() *request.Factory
- func (m *Manager) Scopes() []string
- func (m *Manager) Secret() []byte
- func (m *Manager) Tracer() Tracer
- func (m *Manager) ValidateProfile(p *Profile) error
- func (m *Manager) ValidateState(state State) error
- func (m *Manager) WithClientID(clientID string) *Manager
- func (m *Manager) WithClientSecret(clientSecret string) *Manager
- func (m *Manager) WithHostedDomain(hostedDomain string) *Manager
- func (m *Manager) WithRedirectURI(redirectURI string) *Manager
- func (m *Manager) WithScopes(scopes ...string) *Manager
- func (m *Manager) WithSecret(secret []byte) *Manager
- func (m *Manager) WithTracer(tracer Tracer) *Manager
- type Profile
- type Response
- type Result
- type State
- type TraceFinisher
- type Tracer
- type Values
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultScopes is the default oauth scopes. DefaultScopes = []string{ "openid", "email", "profile", } )
Functions ¶
func SerializeState ¶
SerializeState serializes the oauth state.
Types ¶
type Config ¶
type Config struct { // Secret is an encryption key used to verify oauth state. Secret string `json:"secret,omitempty" yaml:"secret,omitempty" env:"OAUTH_SECRET"` // RedirectURI is the oauth return url. RedirectURI string `json:"redirectURI" yaml:"redirectURI" env:"OAUTH_REDIRECT_URI"` // HostedDomain is a specific domain we want to filter identities to. HostedDomain string `json:"hostedDomain" yaml:"hostedDomain" env:"OAUTH_HOSTED_DOMAIN"` Scopes []string `json:"scopes" yaml:"scopes"` // ClientID is part of the oauth credential pair. ClientID string `json:"clientID" yaml:"clientID" env:"OAUTH_CLIENT_ID"` // ClientSecret is part of the oauth credential pair. ClientSecret string `json:"clientSecret" yaml:"clientSecret" env:"OAUTH_CLIENT_SECRET"` }
Config is the config options.
func MustNewConfigFromEnv ¶
func MustNewConfigFromEnv() *Config
MustNewConfigFromEnv returns a new config from the environment and panics if there is an error.
func NewConfigFromEnv ¶
NewConfigFromEnv creates a new config from the environment.
func (Config) GetClientID ¶
GetClientID returns a property or a default.
func (Config) GetClientSecret ¶
GetClientSecret returns a property or a default.
func (Config) GetHostedDomain ¶
GetHostedDomain returns a property or a default.
func (Config) GetRedirectURI ¶
GetRedirectURI returns a property or a default.
type Error ¶
type Error string
Error is an error string.
const ( // ErrCodeMissing is returned if the code was missing from an oauth return request. ErrCodeMissing Error = "state missing from request" // ErrStateMissing is returned if the state was missing from an oauth return request. ErrStateMissing Error = "state missing from request" // ErrInvalidHostedDomain is an error returned if the JWT hosted zone doesn't match any of the whitelisted domains. ErrInvalidHostedDomain Error = "hosted domain validation failed" // ErrInvalidAntiforgeryToken is an error returns on oauth finish that indicates we didn't originate the auth request. ErrInvalidAntiforgeryToken Error = "invalid anti-forgery token" // ErrFailedCodeExchange happens if the code exchange for an access token fails. ErrFailedCodeExchange Error = "oauth code exchange failed" // ErrGoogleResponseStatus is an error that can occur when querying the google apis. ErrGoogleResponseStatus Error = "google returned a non 2xx response" // ErrProfileJSONUnmarshal is an error returned if the json unmarshal failed. ErrProfileJSONUnmarshal Error = "profile json unmarshal failed" // ErrSecretRequired is a configuration error indicating we did not provide a secret. ErrSecretRequired Error = "manager secret required" // ErrClientIDRequired is a self validation error. ErrClientIDRequired Error = "clientID is required" // ErrClientSecretRequired is a self validation error. ErrClientSecretRequired Error = "clientSecret is required" // ErrRedirectURIRequired is a self validation error. ErrRedirectURIRequired Error = "redirectURI is required" // ErrInvalidRedirectURI is an error in validating the redirect uri. ErrInvalidRedirectURI Error = "invalid redirectURI" )
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is the oauth manager.
func MustNewFromEnv ¶
func MustNewFromEnv() *Manager
MustNewFromEnv returns a new manager from the environment and will panic if there is an error.
func New ¶
func New() *Manager
New returns a new manager. By default it will error if you try and validate a profile. You must either enable `SkipDomainvalidation` or provide valid domains.
func NewFromConfig ¶
NewFromConfig returns a new oauth manager from a config.
func NewFromEnv ¶
NewFromEnv returns a new manager from the environment.
func (*Manager) ClientSecret ¶
ClientSecret returns a client secret.
func (*Manager) CreateState ¶
CreateState creates auth state.
func (*Manager) FetchProfile ¶
func (m *Manager) FetchProfile(ctx context.Context, accessToken string) (profile Profile, err error)
FetchProfile gets a google profile for an access token.
func (*Manager) Finish ¶
Finish processes the returned code, exchanging for an access token, and fetches the user profile.
func (*Manager) HostedDomain ¶
HostedDomain returns the hosted domain.
func (*Manager) OAuthURL ¶
OAuthURL is the auth url for google with a given clientID. This is typically the link that a user will click on to start the auth process.
func (*Manager) RedirectURI ¶
RedirectURI returns a property.
func (*Manager) RequestCreator ¶
RequestCreator returns the request creator.
func (*Manager) ValidateProfile ¶
ValidateProfile validates a profile.
func (*Manager) ValidateState ¶
ValidateState validates oauth state.
func (*Manager) WithClientID ¶
WithClientID sets the client id.
func (*Manager) WithClientSecret ¶
WithClientSecret sets the client id.
func (*Manager) WithHostedDomain ¶
WithHostedDomain returns the hosted domain.
func (*Manager) WithRedirectURI ¶
WithRedirectURI sets the return url.
func (*Manager) WithScopes ¶
WithScopes sets the oauth scopes.
func (*Manager) WithSecret ¶
WithSecret sets the secret used to create state tokens.
func (*Manager) WithTracer ¶
WithTracer sets the oauth manager tracer.
type Profile ¶
type Profile struct { ID string `json:"id"` Email string `json:"email"` VerifiedEmail bool `json:"verified_email"` Name string `json:"name"` GivenName string `json:"given_name"` FamilyName string `json:"family_name"` Link string `json:"link"` Gender string `json:"gender"` Locale string `json:"locale"` PictureURL string `json:"picture"` }
Profile is a profile with google.
type Result ¶
Result is the final result of the oauth exchange. It is the user profile of the user and the state information.
type State ¶
type State struct { // Token is a plaintext random token. Token string // SecureToken is the hashed version of the token. // If a key is set, it validates that our app created the oauth state. SecureToken string // RedirectURL is the redirect url. RedirectURL string }
State is the oauth state.
func DeserializeState ¶
DeserializeState deserializes the oauth state.
type TraceFinisher ¶
TraceFinisher is a finisher for a trace.
type Tracer ¶
type Tracer interface {
Start(r *http.Request) TraceFinisher
}
Tracer is a trace shim.