From 840ad7eefe2b49ab453b9a89b153a264a8c9f8a2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 12 Nov 2024 13:33:35 -0800 Subject: Disable Oauth check if oauth disabled (#32368) Fix #32367 --------- Co-authored-by: Giteabot Co-authored-by: wxiaoguang --- services/auth/oauth2.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'services') diff --git a/services/auth/oauth2.go b/services/auth/oauth2.go index 523998a634..d0aec085b1 100644 --- a/services/auth/oauth2.go +++ b/services/auth/oauth2.go @@ -27,10 +27,15 @@ var ( // CheckOAuthAccessToken returns uid of user from oauth token func CheckOAuthAccessToken(ctx context.Context, accessToken string) int64 { - // JWT tokens require a "." + if !setting.OAuth2.Enabled { + return 0 + } + + // JWT tokens require a ".", if the token isn't like that, return early if !strings.Contains(accessToken, ".") { return 0 } + token, err := oauth2_provider.ParseToken(accessToken, oauth2_provider.DefaultSigningKey) if err != nil { log.Trace("oauth2.ParseToken: %v", err) -- cgit v1.2.3