mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Map OIDC groups to Orgs/Teams (#21441)
Fixes #19555 Test-Instructions: https://github.com/go-gitea/gitea/pull/21441#issuecomment-1419438000 This PR implements the mapping of user groups provided by OIDC providers to orgs teams in Gitea. The main part is a refactoring of the existing LDAP code to make it usable from different providers. Refactorings: - Moved the router auth code from module to service because of import cycles - Changed some model methods to take a `Context` parameter - Moved the mapping code from LDAP to a common location I've tested it with Keycloak but other providers should work too. The JSON mapping format is the same as for LDAP.  --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		@@ -36,7 +36,6 @@ import (
 | 
			
		||||
	"code.gitea.io/gitea/modules/typesniffer"
 | 
			
		||||
	"code.gitea.io/gitea/modules/util"
 | 
			
		||||
	"code.gitea.io/gitea/modules/web/middleware"
 | 
			
		||||
	"code.gitea.io/gitea/services/auth"
 | 
			
		||||
 | 
			
		||||
	"gitea.com/go-chi/cache"
 | 
			
		||||
	"gitea.com/go-chi/session"
 | 
			
		||||
@@ -659,37 +658,6 @@ func getCsrfOpts() CsrfOptions {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Auth converts auth.Auth as a middleware
 | 
			
		||||
func Auth(authMethod auth.Method) func(*Context) {
 | 
			
		||||
	return func(ctx *Context) {
 | 
			
		||||
		var err error
 | 
			
		||||
		ctx.Doer, err = authMethod.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Error("Failed to verify user %v: %v", ctx.Req.RemoteAddr, err)
 | 
			
		||||
			ctx.Error(http.StatusUnauthorized, "Verify")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		if ctx.Doer != nil {
 | 
			
		||||
			if ctx.Locale.Language() != ctx.Doer.Language {
 | 
			
		||||
				ctx.Locale = middleware.Locale(ctx.Resp, ctx.Req)
 | 
			
		||||
			}
 | 
			
		||||
			ctx.IsBasicAuth = ctx.Data["AuthedMethod"].(string) == auth.BasicMethodName
 | 
			
		||||
			ctx.IsSigned = true
 | 
			
		||||
			ctx.Data["IsSigned"] = ctx.IsSigned
 | 
			
		||||
			ctx.Data["SignedUser"] = ctx.Doer
 | 
			
		||||
			ctx.Data["SignedUserID"] = ctx.Doer.ID
 | 
			
		||||
			ctx.Data["SignedUserName"] = ctx.Doer.Name
 | 
			
		||||
			ctx.Data["IsAdmin"] = ctx.Doer.IsAdmin
 | 
			
		||||
		} else {
 | 
			
		||||
			ctx.Data["SignedUserID"] = int64(0)
 | 
			
		||||
			ctx.Data["SignedUserName"] = ""
 | 
			
		||||
 | 
			
		||||
			// ensure the session uid is deleted
 | 
			
		||||
			_ = ctx.Session.Delete("uid")
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Contexter initializes a classic context for a request.
 | 
			
		||||
func Contexter(ctx context.Context) func(next http.Handler) http.Handler {
 | 
			
		||||
	_, rnd := templates.HTMLRenderer(ctx)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user