mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-28 01:05:20 +02:00
Backport #38591 Co-authored-by: Mitrahsoft <bala.c@mitrahsoft.in> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -207,9 +207,24 @@ func IntrospectOAuth(ctx *context.Context) {
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func oauthDoerAuthorizePreCheck(ctx *context.Context, formState string) bool {
|
||||
if ctx.DoerNeedTwoFactorAuth() {
|
||||
handleAuthorizeError(ctx, AuthorizeError{
|
||||
ErrorCode: ErrorCodeAccessDenied,
|
||||
ErrorDescription: "two-factor authentication is required",
|
||||
State: formState,
|
||||
}, "")
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// AuthorizeOAuth manages authorize requests
|
||||
func AuthorizeOAuth(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.AuthorizationForm)
|
||||
if !oauthDoerAuthorizePreCheck(ctx, form.State) {
|
||||
return
|
||||
}
|
||||
errs := binding.Errors{}
|
||||
errs = form.Validate(ctx.Req, errs)
|
||||
if len(errs) > 0 {
|
||||
@@ -385,6 +400,10 @@ func AuthorizeOAuth(ctx *context.Context) {
|
||||
// GrantApplicationOAuth manages the post request submitted when a user grants access to an application
|
||||
func GrantApplicationOAuth(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.GrantApplicationForm)
|
||||
if !oauthDoerAuthorizePreCheck(ctx, form.State) {
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.Session.Get("client_id") != form.ClientID || ctx.Session.Get("state") != form.State ||
|
||||
ctx.Session.Get("redirect_uri") != form.RedirectURI {
|
||||
ctx.HTTPError(http.StatusBadRequest)
|
||||
|
||||
Reference in New Issue
Block a user