diff --git a/routers/web/auth/oauth2_provider.go b/routers/web/auth/oauth2_provider.go index 7b473ed0ec..a9b8b63940 100644 --- a/routers/web/auth/oauth2_provider.go +++ b/routers/web/auth/oauth2_provider.go @@ -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)