Skip to content

Commit a6e86dd

Browse files
author
Nils Hillmann
committed
Merge branch 'feature/oauth_userinfo' of https://scm.nlh-software.de/nlhsoftware/gitea into feature/oauth_userinfo
2 parents 071363a + f76f63e commit a6e86dd

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

routers/user/oauth.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,19 @@ func InfoOAuth(ctx *context.Context) {
236236
})
237237
return
238238
}
239-
if uid != 0 {
240-
authUser, err := models.GetUserByID(uid)
241-
if err != nil {
242-
ctx.ServerError("GetUserByID", err)
243-
return
244-
}
245-
response := &userInfoResponse{
246-
Sub: fmt.Sprint(authUser.ID),
247-
Name: authUser.FullName,
248-
Username: authUser.Name,
249-
Email: authUser.Email,
250-
Picture: authUser.AvatarLink(),
251-
}
252-
ctx.JSON(http.StatusOK, response)
239+
authUser, err := models.GetUserByID(uid)
240+
if err != nil {
241+
ctx.ServerError("GetUserByID", err)
242+
return
243+
}
244+
response := &userInfoResponse{
245+
Sub: fmt.Sprint(authUser.ID),
246+
Name: authUser.FullName,
247+
Username: authUser.Name,
248+
Email: authUser.Email,
249+
Picture: authUser.AvatarLink(),
253250
}
251+
ctx.JSON(http.StatusOK, response)
254252
}
255253

256254
// AuthorizeOAuth manages authorize requests
@@ -634,13 +632,15 @@ func handleAuthorizeError(ctx *context.Context, authErr AuthorizeError, redirect
634632

635633
func handleBearerTokenError(ctx *context.Context, beErr BearerTokenError) {
636634
ctx.Resp.Header().Set("WWW-Authenticate", fmt.Sprintf("Bearer realm=\"\", error=\"%s\", error_description=\"%s\"", beErr.ErrorCode, beErr.ErrorDescription))
637-
if beErr.ErrorCode == BearerTokenErrorCodeInvalidRequest {
635+
switch beErr.ErrorCode {
636+
case BearerTokenErrorCodeInvalidRequest:
638637
ctx.JSON(http.StatusBadRequest, beErr)
639-
}
640-
if beErr.ErrorCode == BearerTokenErrorCodeInvalidToken {
638+
case BearerTokenErrorCodeInvalidToken:
641639
ctx.JSON(http.StatusUnauthorized, beErr)
642-
}
643-
if beErr.ErrorCode == BearerTokenErrorCodeInsufficientScope {
640+
case BearerTokenErrorCodeInsufficientScope:
644641
ctx.JSON(http.StatusForbidden, beErr)
642+
default:
643+
log.Error("Invalid BearerTokenErrorCode: %v", beErr.ErrorCode)
644+
ctx.ServerError("Unhandled BearerTokenError", fmt.Errorf("BearerTokenError: error=\"%v\", error_description=\"%v\"", beErr.ErrorCode, beErr.ErrorDescription))
645645
}
646646
}

0 commit comments

Comments
 (0)