loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

use existing oauth grant for public client (#31015)

Do not try to create a new authorization grant when one exists already,
thus preventing a DB-related authorization issue.

Fix https://github.com/go-gitea/gitea/pull/30790#issuecomment-2118812426

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
(cherry picked from commit 9c8c9ff6d10b35de8d2d7eae0fc2646ad9bbe94a)

authored by

Denys Konovalov
Lunny Xiao
and committed by
Earl Warren
07fe5a8b 7d7ea454

+17 -2
+17 -2
routers/web/auth/oauth.go
··· 557 557 ctx.ServerError("GetOAuth2ApplicationByClientID", err) 558 558 return 559 559 } 560 - grant, err := app.CreateGrant(ctx, ctx.Doer.ID, form.Scope) 560 + grant, err := app.GetGrantByUserID(ctx, ctx.Doer.ID) 561 561 if err != nil { 562 + handleServerError(ctx, form.State, form.RedirectURI) 563 + return 564 + } 565 + if grant == nil { 566 + grant, err = app.CreateGrant(ctx, ctx.Doer.ID, form.Scope) 567 + if err != nil { 568 + handleAuthorizeError(ctx, AuthorizeError{ 569 + State: form.State, 570 + ErrorDescription: "cannot create grant for user", 571 + ErrorCode: ErrorCodeServerError, 572 + }, form.RedirectURI) 573 + return 574 + } 575 + } else if grant.Scope != form.Scope { 562 576 handleAuthorizeError(ctx, AuthorizeError{ 563 577 State: form.State, 564 - ErrorDescription: "cannot create grant for user", 578 + ErrorDescription: "a grant exists with different scope", 565 579 ErrorCode: ErrorCodeServerError, 566 580 }, form.RedirectURI) 567 581 return 568 582 } 583 + 569 584 if len(form.Nonce) > 0 { 570 585 err := grant.SetNonce(ctx, form.Nonce) 571 586 if err != nil {