Documentation ¶
Index ¶
- func ProviderList() []string
- func RegisterProvider(p Provider)
- func StartFlow(cfg Config, w http.ResponseWriter)
- func UnRegisterProvider(name string)
- type Config
- type GithubUser
- type GitlabGroup
- type GitlabUser
- type GoogleUser
- type JSONError
- type Manager
- func (manager *Manager) AddConfig(providerName string, opts map[string]string) error
- func (manager *Manager) GetConfigFromRequest(r *http.Request) (Config, error)
- func (manager *Manager) GetConfigs() map[string]Config
- func (manager *Manager) Handle(w http.ResponseWriter, r *http.Request) (startedFlow bool, authenticated bool, userInfo model.UserInfo, err error)
- type Provider
- type TokenInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProviderList ¶
func ProviderList() []string
ProviderList returns the names of all registered provider
func StartFlow ¶
func StartFlow(cfg Config, w http.ResponseWriter)
StartFlow by redirecting the user to the login provider. A state parameter to protect against cross-site request forgery attacks is randomly generated and stored in a cookie
func UnRegisterProvider ¶
func UnRegisterProvider(name string)
UnRegisterProvider removes a provider
Types ¶
type Config ¶
type Config struct { // ClientID is the application's ID. ClientID string // ClientSecret is the application's secret. ClientSecret string // The oauth authentication url to redirect to AuthURL string // The url for token exchange TokenURL string // RedirectURL is the URL to redirect users going through // the OAuth flow, after the resource owner's URLs. RedirectURI string // Scope specifies optional requested permissions, this is a *space* separated list. Scope string // The oauth provider Provider Provider }
Config describes a typical 3-legged OAuth2 flow, with both the client application information and the server's endpoint URLs.
type GithubUser ¶
type GithubUser struct { Login string `json:"login,omitempty"` AvatarURL string `json:"avatar_url,omitempty"` Name string `json:"name,omitempty"` Email string `json:"email,omitempty"` }
GithubUser is used for parsing the github response
type GitlabGroup ¶ added in v1.3.0
type GitlabGroup struct {
FullPath string `json:"full_path,omitempty"`
}
type GitlabUser ¶ added in v1.3.0
type GitlabUser struct { Username string `json:"username,omitempty"` AvatarURL string `json:"avatar_url,omitempty"` Name string `json:"name,omitempty"` Email string `json:"email,omitempty"` }
GitlabUser is used for parsing the gitlab response
type GoogleUser ¶ added in v1.1.0
type JSONError ¶
type JSONError struct {
Error string `json:"error"`
}
JSONError represents an oauth error response in json form.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager has the responsibility to handle the user user requests in an oauth flow. It has to pick the right configuration and start the oauth redirecting.
func (*Manager) GetConfigFromRequest ¶
GetConfigFromRequest returns the oauth configuration matching the current path. The configuration name is taken from the last path segment.
func (*Manager) GetConfigs ¶
GetConfigs of the manager
func (*Manager) Handle ¶
func (manager *Manager) Handle(w http.ResponseWriter, r *http.Request) ( startedFlow bool, authenticated bool, userInfo model.UserInfo, err error)
Handle is managing the oauth flow. Dependent on the code parameter of the url, the oauth flow is started or the call is interpreted as the redirect callback and the token exchange is done. Return parameters:
startedFlow - true, if this was the initial call to start the oauth flow authenticated - if the authentication was successful or not userInfo - the user info from the provider in case of a successful authentication err - an error
type Provider ¶
type Provider struct { // The name to access the provider in the configuration Name string // The oauth authentication url to redirect to AuthURL string // The url for token exchange TokenURL string // Default Scopes is a space separated list of oauth scopes to use for this provider. // This list can be overwritten by configuration. DefaultScopes string // GetUserInfo is a provider specific Implementation // for fetching the user information. // Possible keys in the returned map are: // username, email, name GetUserInfo func(token TokenInfo) (u model.UserInfo, rawUserJson string, err error) }
Provider is the description of an oauth provider adapter
func GetProvider ¶
GetProvider returns a provider
type TokenInfo ¶
type TokenInfo struct { // AccessToken is the token that authorizes and authenticates // the requests. AccessToken string `json:"access_token"` // TokenType is the type of token. TokenType string `json:"token_type,omitempty"` // The scopes for this tolen Scope string `json:"scope,omitempty"` }
TokenInfo represents the credentials used to authorize the requests to access protected resources on the OAuth 2.0 provider's backend.