Add Name to oauth2.Provider

Providers should be able to tell us their name. This will help construct
routes.
pull/922/head
Tim Raymond 2017-02-14 17:28:05 -05:00
parent 633a586d6f
commit f01e3b18fe
2 changed files with 23 additions and 15 deletions

View File

@ -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{

View File

@ -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