Skip to content

Commit 8a259e5

Browse files
GiteaBotZettat123KN4CK3R
authored
Return access_denied error when an OAuth2 request is denied (#30974) (#31029)
Backport #30974 by Zettat123 Co-authored-by: Zettat123 <[email protected]> Co-authored-by: KN4CK3R <[email protected]>
1 parent 8663a35 commit 8a259e5

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

routers/web/auth/oauth.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,16 @@ func GrantApplicationOAuth(ctx *context.Context) {
541541
ctx.Error(http.StatusBadRequest)
542542
return
543543
}
544+
545+
if !form.Granted {
546+
handleAuthorizeError(ctx, AuthorizeError{
547+
State: form.State,
548+
ErrorDescription: "the request is denied",
549+
ErrorCode: ErrorCodeAccessDenied,
550+
}, form.RedirectURI)
551+
return
552+
}
553+
544554
app, err := auth.GetOAuth2ApplicationByClientID(ctx, form.ClientID)
545555
if err != nil {
546556
ctx.ServerError("GetOAuth2ApplicationByClientID", err)

services/forms/user_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func (f *AuthorizationForm) Validate(req *http.Request, errs binding.Errors) bin
161161
// GrantApplicationForm form for authorizing oauth2 clients
162162
type GrantApplicationForm struct {
163163
ClientID string `binding:"Required"`
164+
Granted bool
164165
RedirectURI string
165166
State string
166167
Scope string

templates/user/auth/grant.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
<input type="hidden" name="scope" value="{{.Scope}}">
2424
<input type="hidden" name="nonce" value="{{.Nonce}}">
2525
<input type="hidden" name="redirect_uri" value="{{.RedirectURI}}">
26-
<button type="submit" id="authorize-app" value="{{ctx.Locale.Tr "auth.authorize_application"}}" class="ui red inline button">{{ctx.Locale.Tr "auth.authorize_application"}}</button>
27-
<a href="{{.RedirectURI}}" class="ui basic primary inline button">Cancel</a>
26+
<button type="submit" id="authorize-app" name="granted" value="true" class="ui red inline button">{{ctx.Locale.Tr "auth.authorize_application"}}</button>
27+
<button type="submit" name="granted" value="false" class="ui basic primary inline button">{{ctx.Locale.Tr "cancel"}}</button>
2828
</form>
2929
</div>
3030
</div>

0 commit comments

Comments
 (0)