Browse Source

Allow users to use a generic oauth that conforms to the github style.

Enables users to set their own link text.
Kevin Fitzpatrick 9 years ago
parent
commit
b4646b6c3a

+ 2 - 0
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

+ 3 - 2
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

+ 17 - 1
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,
+			}
+		}
 	}
 }
 

+ 3 - 1
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;
 

+ 4 - 0
public/app/partials/login.html

@@ -59,6 +59,10 @@
 						<i class="fa fa-github"></i>
 						with Github
 					</a>
+					<a class="btn btn-large btn-generic-oauth" href="login/generic-oauth" target="_self" ng-if="genericOAuthEnabled">
+						<i class="fa fa-gear"></i>
+            with {{oauthProviderName || "OAuth 2"}}
+          </a>
 				</div>
 			</div>