@@ -236,21 +236,19 @@ func InfoOAuth(ctx *context.Context) {
236
236
})
237
237
return
238
238
}
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 (),
253
250
}
251
+ ctx .JSON (http .StatusOK , response )
254
252
}
255
253
256
254
// AuthorizeOAuth manages authorize requests
@@ -634,13 +632,15 @@ func handleAuthorizeError(ctx *context.Context, authErr AuthorizeError, redirect
634
632
635
633
func handleBearerTokenError (ctx * context.Context , beErr BearerTokenError ) {
636
634
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 :
638
637
ctx .JSON (http .StatusBadRequest , beErr )
639
- }
640
- if beErr .ErrorCode == BearerTokenErrorCodeInvalidToken {
638
+ case BearerTokenErrorCodeInvalidToken :
641
639
ctx .JSON (http .StatusUnauthorized , beErr )
642
- }
643
- if beErr .ErrorCode == BearerTokenErrorCodeInsufficientScope {
640
+ case BearerTokenErrorCodeInsufficientScope :
644
641
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 ))
645
645
}
646
646
}
0 commit comments