Skip to content

Commit c85e24e

Browse files
denyskonlunny
authored andcommitted
use existing oauth grant for public client
1 parent 1007ce7 commit c85e24e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

routers/web/auth/oauth.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,22 @@ func GrantApplicationOAuth(ctx *context.Context) {
556556
ctx.ServerError("GetOAuth2ApplicationByClientID", err)
557557
return
558558
}
559-
grant, err := app.CreateGrant(ctx, ctx.Doer.ID, form.Scope)
559+
grant, err := app.GetGrantByUserID(ctx, ctx.Doer.ID)
560560
if err != nil {
561-
handleAuthorizeError(ctx, AuthorizeError{
562-
State: form.State,
563-
ErrorDescription: "cannot create grant for user",
564-
ErrorCode: ErrorCodeServerError,
565-
}, form.RedirectURI)
561+
handleServerError(ctx, form.State, form.RedirectURI)
566562
return
567563
}
564+
if grant == nil {
565+
grant, err = app.CreateGrant(ctx, ctx.Doer.ID, form.Scope)
566+
if err != nil {
567+
handleAuthorizeError(ctx, AuthorizeError{
568+
State: form.State,
569+
ErrorDescription: "cannot create grant for user",
570+
ErrorCode: ErrorCodeServerError,
571+
}, form.RedirectURI)
572+
return
573+
}
574+
}
568575
if len(form.Nonce) > 0 {
569576
err := grant.SetNonce(ctx, form.Nonce)
570577
if err != nil {

0 commit comments

Comments
 (0)