From b4627983b9ce19f8e527d5c98b657502a2374b49 Mon Sep 17 00:00:00 2001 From: Kent Wang Date: Fri, 16 Jun 2017 17:35:57 +0800 Subject: [PATCH] Add redirect url to generic oauth --- oauth2/generic.go | 2 ++ server/server.go | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/oauth2/generic.go b/oauth2/generic.go index 34f5fa1da..aa18e716f 100644 --- a/oauth2/generic.go +++ b/oauth2/generic.go @@ -23,6 +23,7 @@ type Generic struct { ClientSecret string RequiredScopes []string Domains []string // Optional email domain checking + RedirectURL string AuthURL string TokenURL string APIURL string // APIURL returns OpenID Userinfo @@ -58,6 +59,7 @@ func (g *Generic) Config() *oauth2.Config { ClientID: g.ID(), ClientSecret: g.Secret(), Scopes: g.Scopes(), + RedirectURL: g.RedirectURL, Endpoint: oauth2.Endpoint{ AuthURL: g.AuthURL, TokenURL: g.TokenURL, diff --git a/server/server.go b/server/server.go index b86cde6ae..d3617d9e9 100644 --- a/server/server.go +++ b/server/server.go @@ -61,7 +61,7 @@ type Server struct { GoogleClientID string `long:"google-client-id" description:"Google Client ID for OAuth 2 support" env:"GOOGLE_CLIENT_ID"` GoogleClientSecret string `long:"google-client-secret" description:"Google Client Secret for OAuth 2 support" env:"GOOGLE_CLIENT_SECRET"` GoogleDomains []string `long:"google-domains" description:"Google email domain user is required to have active membership" env:"GOOGLE_DOMAINS" env-delim:","` - PublicURL string `long:"public-url" description:"Full public URL used to access Chronograf from a web browser. Used for Google OAuth2 authentication. (http://localhost:8888)" env:"PUBLIC_URL"` + PublicURL string `long:"public-url" description:"Full public URL used to access Chronograf from a web browser. Used for OAuth2 authentication. (http://localhost:8888)" env:"PUBLIC_URL"` HerokuClientID string `long:"heroku-client-id" description:"Heroku Client ID for OAuth 2 support" env:"HEROKU_CLIENT_ID"` HerokuSecret string `long:"heroku-secret" description:"Heroku Secret for OAuth 2 support" env:"HEROKU_SECRET"` @@ -155,12 +155,19 @@ func (s *Server) herokuOAuth(logger chronograf.Logger, auth oauth2.Authenticator } func (s *Server) genericOAuth(logger chronograf.Logger, auth oauth2.Authenticator) (oauth2.Provider, oauth2.Mux, func() bool) { + name := "generic" + if s.GenericName != "" { + name = s.GenericName + } + + redirectURL := s.PublicURL + s.Basepath + "/oauth/" + name + "/callback" gen := oauth2.Generic{ PageName: s.GenericName, ClientID: s.GenericClientID, ClientSecret: s.GenericClientSecret, RequiredScopes: s.GenericScopes, Domains: s.GenericDomains, + RedirectURL: redirectURL, AuthURL: s.GenericAuthURL, TokenURL: s.GenericTokenURL, APIURL: s.GenericAPIURL,