From d048e39cde9101c39e9ba4bcb27673b97892160e Mon Sep 17 00:00:00 2001 From: William Wei Date: Wed, 15 Apr 2015 14:03:28 +0800 Subject: [PATCH 1/2] grafana/grafana#1781 add oauth api url as config --- conf/defaults.ini | 2 ++ conf/sample.ini | 2 ++ pkg/social/social.go | 1 + 3 files changed, 5 insertions(+) diff --git a/conf/defaults.ini b/conf/defaults.ini index 1ba6dd2be66..5035941b2ec 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -141,6 +141,7 @@ client_secret = some_secret scopes = user:email auth_url = https://github.com/login/oauth/authorize token_url = https://github.com/login/oauth/access_token +api_url = https://api.github.com/user # Uncomment bellow to only allow specific email domains ; allowed_domains = mycompany.com othercompany.com @@ -152,6 +153,7 @@ client_secret = some_client_secret scopes = https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email auth_url = https://accounts.google.com/o/oauth2/auth token_url = https://accounts.google.com/o/oauth2/token +api_url = https://www.googleapis.com/oauth2/v1/userinfo allowed_domains = #################################### Logging ########################## diff --git a/conf/sample.ini b/conf/sample.ini index 9a340c74975..6aaa69f7314 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -141,6 +141,7 @@ ;scopes = user:email ;auth_url = https://github.com/login/oauth/authorize ;token_url = https://github.com/login/oauth/access_token +;api_url = https://api.github.com/user # Uncomment bellow to only allow specific email domains ; allowed_domains = mycompany.com othercompany.com @@ -152,6 +153,7 @@ ;scopes = https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email ;auth_url = https://accounts.google.com/o/oauth2/auth ;token_url = https://accounts.google.com/o/oauth2/token +;api_url = https://www.googleapis.com/oauth2/v1/userinfo # Uncomment bellow to only allow specific email domains ; allowed_domains = mycompany.com othercompany.com diff --git a/pkg/social/social.go b/pkg/social/social.go index d5ff8a4ee75..cd1c278980a 100644 --- a/pkg/social/social.go +++ b/pkg/social/social.go @@ -49,6 +49,7 @@ func NewOAuthService() { Scopes: sec.Key("scopes").Strings(" "), AuthUrl: sec.Key("auth_url").String(), TokenUrl: sec.Key("token_url").String(), + APIUrl: sec.Key("api_url").String(), Enabled: sec.Key("enabled").MustBool(), AllowedDomains: sec.Key("allowed_domains").Strings(" "), } From 4fd2622e55d7dd859e4c278e75be26886c65e9c0 Mon Sep 17 00:00:00 2001 From: William Wei Date: Wed, 15 Apr 2015 14:18:10 +0800 Subject: [PATCH 2/2] grafana/grafana#1781 add oauth api url as config read github api from config file instead of using public github: http://api.github.com/user this would be useful when you are using github enterprise edition --- pkg/social/social.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/social/social.go b/pkg/social/social.go index cd1c278980a..f75b98b4210 100644 --- a/pkg/social/social.go +++ b/pkg/social/social.go @@ -73,7 +73,7 @@ func NewOAuthService() { // GitHub. if name == "github" { setting.OAuthService.GitHub = true - SocialMap["github"] = &SocialGithub{Config: &config, allowedDomains: info.AllowedDomains} + SocialMap["github"] = &SocialGithub{Config: &config, allowedDomains: info.AllowedDomains, APIUrl: info.APIUrl} } // Google. @@ -101,6 +101,7 @@ func isEmailAllowed(email string, allowedDomains []string) bool { type SocialGithub struct { *oauth2.Config allowedDomains []string + APIUrl []string } func (s *SocialGithub) Type() int { @@ -120,7 +121,7 @@ func (s *SocialGithub) UserInfo(token *oauth2.Token) (*BasicUserInfo, error) { var err error client := s.Client(oauth2.NoContext, token) - r, err := client.Get("https://api.github.com/user") + r, err := client.Get(s.APIUrl) if err != nil { return nil, err }