Skip to content

Commit 888e0a9

Browse files
imgurbot12aliev
authored andcommitted
feat: access-denied exception on scope denial
1 parent bda9a03 commit 888e0a9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

examples/fastapi_example.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
from sqlmodel.ext.asyncio.session import AsyncSession
1616

1717
from aioauth.collections import HTTPHeaderDict
18+
from aioauth.errors import AccessDeniedError
1819
from aioauth.requests import Post, Query
1920
from aioauth.requests import Request as OAuthRequest
2021
from aioauth.responses import Response as OAuthResponse
2122
from aioauth.types import RequestMethod
23+
from aioauth.utils import build_error_response
2224

2325
from shared import AuthServer, BackendStore, engine, settings, try_login, lifespan
2426

@@ -174,14 +176,18 @@ async def approve_submit(
174176
approval: int = Form(),
175177
oauth: AuthServer = Depends(get_auth_server),
176178
):
177-
""" """
179+
"""
180+
scope approval form submission handler
181+
"""
178182
oauthreq = request.session["oauth"]
179183
oauthreq.user = request.session["user"]
180184
if not approval:
181-
# TODO: generate `permission_denied` response
182-
return await approve(request)
183-
# process authorize request
184-
response = await oauth.create_authorization_response(oauthreq)
185+
# generate error response on deny
186+
error = AccessDeniedError(oauthreq, 'User rejected scopes')
187+
response = build_error_response(error, oauthreq, skip_redirect_on_exc=())
188+
else:
189+
# process authorize request
190+
response = await oauth.create_authorization_response(oauthreq)
185191
return to_response(response)
186192

187193

0 commit comments

Comments
 (0)