From 311df9c521f05cdca880152e73dbed47afb74cde Mon Sep 17 00:00:00 2001 From: haixunlu Date: Tue, 18 Dec 2018 12:49:30 -0800 Subject: auth: add new authentication source: GitHub, including GitHub Enterprise (#5340) * Add new Authentication Source: GitHub, including GitHub Enterprise. * Add vendor dependencies. --- routes/admin/auths.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'routes/admin') diff --git a/routes/admin/auths.go b/routes/admin/auths.go index d013c793..a217174a 100644 --- a/routes/admin/auths.go +++ b/routes/admin/auths.go @@ -7,15 +7,16 @@ package admin import ( "fmt" + "strings" + "github.com/Unknwon/com" "github.com/go-xorm/core" - log "gopkg.in/clog.v1" - "github.com/gogs/gogs/models" "github.com/gogs/gogs/pkg/auth/ldap" "github.com/gogs/gogs/pkg/context" "github.com/gogs/gogs/pkg/form" "github.com/gogs/gogs/pkg/setting" + log "gopkg.in/clog.v1" ) const ( @@ -51,6 +52,7 @@ var ( {models.LoginNames[models.LOGIN_DLDAP], models.LOGIN_DLDAP}, {models.LoginNames[models.LOGIN_SMTP], models.LOGIN_SMTP}, {models.LoginNames[models.LOGIN_PAM], models.LOGIN_PAM}, + {models.LoginNames[models.LOGIN_GITHUB], models.LOGIN_GITHUB}, } securityProtocols = []dropdownItem{ {models.SecurityProtocolNames[ldap.SECURITY_PROTOCOL_UNENCRYPTED], ldap.SECURITY_PROTOCOL_UNENCRYPTED}, @@ -138,6 +140,10 @@ func NewAuthSourcePost(c *context.Context, f form.Authentication) { config = &models.PAMConfig{ ServiceName: f.PAMServiceName, } + case models.LOGIN_GITHUB: + config = &models.GITHUBConfig{ + ApiEndpoint: f.GithubApiEndpoint, + } default: c.Error(400) return @@ -220,6 +226,14 @@ func EditAuthSourcePost(c *context.Context, f form.Authentication) { config = &models.PAMConfig{ ServiceName: f.PAMServiceName, } + case models.LOGIN_GITHUB: + var apiEndpoint = f.GithubApiEndpoint + if !strings.HasSuffix(apiEndpoint, "/") { + apiEndpoint += "/" + } + config = &models.GITHUBConfig{ + ApiEndpoint: apiEndpoint, + } default: c.Error(400) return -- cgit v1.2.3