diff --git a/oauth2/github.go b/oauth2/github.go index 636a7983c..67395e4d8 100644 --- a/oauth2/github.go +++ b/oauth2/github.go @@ -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{ diff --git a/oauth2/oauth2.go b/oauth2/oauth2.go index 151fd1c93..d29046d49 100644 --- a/oauth2/oauth2.go +++ b/oauth2/oauth2.go @@ -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