Add Name to oauth2.Provider
Providers should be able to tell us their name. This will help construct routes.pull/922/head
parent
633a586d6f
commit
f01e3b18fe
|
@ -15,6 +15,21 @@ import (
|
|||
|
||||
var _ Provider = &Github{}
|
||||
|
||||
// NewGithub constructs a Github with default scopes.
|
||||
func NewGithub(clientID, clientSecret string, orgs []string, auth Authenticator, log chronograf.Logger) Github {
|
||||
scopes := []string{"user:email"}
|
||||
if len(orgs) > 0 {
|
||||
scopes = append(scopes, "read:org")
|
||||
}
|
||||
return Github{
|
||||
ClientID: clientID,
|
||||
ClientSecret: clientSecret,
|
||||
Orgs: orgs,
|
||||
Auth: auth,
|
||||
Logger: log,
|
||||
}
|
||||
}
|
||||
|
||||
// Github provides OAuth Login and Callback server. Callback will set
|
||||
// an authentication cookie. This cookie's value is a JWT containing
|
||||
// the user's primary Github email address.
|
||||
|
@ -26,6 +41,11 @@ type Github struct {
|
|||
Logger chronograf.Logger
|
||||
}
|
||||
|
||||
// Name is the name of the provider
|
||||
func (g *Github) Name() string {
|
||||
return "github"
|
||||
}
|
||||
|
||||
// ID returns the github application client id
|
||||
func (g *Github) ID() string {
|
||||
return g.ClientID
|
||||
|
@ -46,21 +66,6 @@ func (g *Github) Scopes() []string {
|
|||
return scopes
|
||||
}
|
||||
|
||||
// NewGithub constructs a Github with default scopes.
|
||||
func NewGithub(clientID, clientSecret string, orgs []string, auth Authenticator, log chronograf.Logger) Github {
|
||||
scopes := []string{"user:email"}
|
||||
if len(orgs) > 0 {
|
||||
scopes = append(scopes, "read:org")
|
||||
}
|
||||
return Github{
|
||||
ClientID: clientID,
|
||||
ClientSecret: clientSecret,
|
||||
Orgs: orgs,
|
||||
Auth: auth,
|
||||
Logger: log,
|
||||
}
|
||||
}
|
||||
|
||||
// Config is the Github OAuth2 exchange information and endpoints
|
||||
func (g *Github) Config() *oauth2.Config {
|
||||
return &oauth2.Config{
|
||||
|
|
|
@ -41,6 +41,9 @@ type Provider interface {
|
|||
Config() *oauth2.Config
|
||||
// PrincipalID with fetch the identifier to be associated with the principal.
|
||||
PrincipalID(provider *http.Client) (string, error)
|
||||
|
||||
// Name is the name of the Provider
|
||||
Name() string
|
||||
}
|
||||
|
||||
// Mux is a collection of handlers responsible for servicing an Oauth2 interaction between a browser and a provider
|
||||
|
|
Loading…
Reference in New Issue