From b4646b6c3a4256a17cab41dacc496d9c885a2544 Mon Sep 17 00:00:00 2001 From: Kevin Fitzpatrick Date: Tue, 12 Apr 2016 17:54:45 -0700 Subject: [PATCH 1/2] Allow users to use a generic oauth that conforms to the github style. Enables users to set their own link text. --- pkg/api/login.go | 2 ++ pkg/setting/setting_oauth.go | 5 +++-- pkg/social/social.go | 18 +++++++++++++++++- public/app/core/controllers/login_ctrl.js | 4 +++- public/app/partials/login.html | 4 ++++ 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/pkg/api/login.go b/pkg/api/login.go index 4f976f753a2..789765ee01e 100644 --- a/pkg/api/login.go +++ b/pkg/api/login.go @@ -27,6 +27,8 @@ func LoginView(c *middleware.Context) { viewData.Settings["googleAuthEnabled"] = setting.OAuthService.Google viewData.Settings["githubAuthEnabled"] = setting.OAuthService.GitHub + viewData.Settings["genericOAuthEnabled"] = setting.OAuthService.Generic + viewData.Settings["oauthProviderName"] = setting.OAuthService.OAuthProviderName viewData.Settings["disableUserSignUp"] = !setting.AllowUserSignUp viewData.Settings["loginHint"] = setting.LoginHint viewData.Settings["allowUserPassLogin"] = setting.AllowUserPassLogin diff --git a/pkg/setting/setting_oauth.go b/pkg/setting/setting_oauth.go index db2f0fb3802..71c4ade1468 100644 --- a/pkg/setting/setting_oauth.go +++ b/pkg/setting/setting_oauth.go @@ -11,8 +11,9 @@ type OAuthInfo struct { } type OAuther struct { - GitHub, Google, Twitter bool - OAuthInfos map[string]*OAuthInfo + GitHub, Google, Twitter, Generic bool + OAuthInfos map[string]*OAuthInfo + OAuthProviderName string } var OAuthService *OAuther diff --git a/pkg/social/social.go b/pkg/social/social.go index 4a8cb8bac5d..402f02449ff 100644 --- a/pkg/social/social.go +++ b/pkg/social/social.go @@ -42,7 +42,7 @@ func NewOAuthService() { setting.OAuthService = &setting.OAuther{} setting.OAuthService.OAuthInfos = make(map[string]*setting.OAuthInfo) - allOauthes := []string{"github", "google"} + allOauthes := []string{"github", "google", "generic-oauth"} for _, name := range allOauthes { sec := setting.Cfg.Section("auth." + name) @@ -98,6 +98,22 @@ func NewOAuthService() { allowSignup: info.AllowSignup, } } + + // Generic - Uses the same scheme as Github. + if name == "generic-oauth" { + setting.OAuthService.Generic = true + setting.OAuthService.OAuthProviderName = sec.Key("oauth_provider_name").String() + teamIds := sec.Key("team_ids").Ints(",") + allowedOrganizations := sec.Key("allowed_organizations").Strings(" ") + SocialMap["generic-oauth"] = &SocialGithub{ + Config: &config, + allowedDomains: info.AllowedDomains, + apiUrl: info.ApiUrl, + allowSignup: info.AllowSignup, + teamIds: teamIds, + allowedOrganizations: allowedOrganizations, + } + } } } diff --git a/public/app/core/controllers/login_ctrl.js b/public/app/core/controllers/login_ctrl.js index 8696d94f4f3..60136a05c0c 100644 --- a/public/app/core/controllers/login_ctrl.js +++ b/public/app/core/controllers/login_ctrl.js @@ -17,8 +17,10 @@ function (angular, coreModule, config) { $scope.googleAuthEnabled = config.googleAuthEnabled; $scope.githubAuthEnabled = config.githubAuthEnabled; - $scope.oauthEnabled = config.githubAuthEnabled || config.googleAuthEnabled; + $scope.oauthEnabled = config.githubAuthEnabled || config.googleAuthEnabled || config.genericOAuthEnabled; $scope.allowUserPassLogin = config.allowUserPassLogin; + $scope.genericOAuthEnabled = config.genericOAuthEnabled; + $scope.oauthProviderName = config.oauthProviderName; $scope.disableUserSignUp = config.disableUserSignUp; $scope.loginHint = config.loginHint; diff --git a/public/app/partials/login.html b/public/app/partials/login.html index 5bee63e6214..200200ee4b9 100644 --- a/public/app/partials/login.html +++ b/public/app/partials/login.html @@ -59,6 +59,10 @@ with Github + + + with {{oauthProviderName || "OAuth 2"}} + From f2baa5b210b2000509bbb2aa319a6bedf238903f Mon Sep 17 00:00:00 2001 From: Kevin Fitzpatrick Date: Wed, 18 May 2016 13:37:04 -0700 Subject: [PATCH 2/2] Make Generic OAuth Configs ENV VARS-friendly Use underscores instead of dashes. --- pkg/social/social.go | 6 +++--- public/app/partials/login.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/social/social.go b/pkg/social/social.go index 402f02449ff..3c970f89e4f 100644 --- a/pkg/social/social.go +++ b/pkg/social/social.go @@ -42,7 +42,7 @@ func NewOAuthService() { setting.OAuthService = &setting.OAuther{} setting.OAuthService.OAuthInfos = make(map[string]*setting.OAuthInfo) - allOauthes := []string{"github", "google", "generic-oauth"} + allOauthes := []string{"github", "google", "generic_oauth"} for _, name := range allOauthes { sec := setting.Cfg.Section("auth." + name) @@ -100,12 +100,12 @@ func NewOAuthService() { } // Generic - Uses the same scheme as Github. - if name == "generic-oauth" { + if name == "generic_oauth" { setting.OAuthService.Generic = true setting.OAuthService.OAuthProviderName = sec.Key("oauth_provider_name").String() teamIds := sec.Key("team_ids").Ints(",") allowedOrganizations := sec.Key("allowed_organizations").Strings(" ") - SocialMap["generic-oauth"] = &SocialGithub{ + SocialMap["generic_oauth"] = &SocialGithub{ Config: &config, allowedDomains: info.AllowedDomains, apiUrl: info.ApiUrl, diff --git a/public/app/partials/login.html b/public/app/partials/login.html index 200200ee4b9..f4f5fb26d7e 100644 --- a/public/app/partials/login.html +++ b/public/app/partials/login.html @@ -59,7 +59,7 @@ with Github - + with {{oauthProviderName || "OAuth 2"}}