@@ -43,26 +43,29 @@ class AuthorizationRequest(BaseModel):
43
43
class Config :
44
44
extra = "ignore"
45
45
46
- def validate_scope (requested_scope : str | None , client : OAuthClientInformationFull ) -> list [str ] | None :
46
+ def validate_scope (requested_scope : str | None , scope : str | None ) -> list [str ] | None :
47
47
if requested_scope is None :
48
48
return None
49
49
requested_scopes = requested_scope .split (" " )
50
- allowed_scopes = [] if client . scope is None else client . scope .split (" " )
50
+ allowed_scopes = [] if scope is None else scope .split (" " )
51
51
for scope in requested_scopes :
52
52
if scope not in allowed_scopes :
53
53
raise InvalidRequestError (f"Client was not registered with scope { scope } " )
54
54
return requested_scopes
55
55
56
- def validate_redirect_uri (auth_request : AuthorizationRequest , client : OAuthClientInformationFull ) -> AnyHttpUrl :
57
- if auth_request .redirect_uri is not None :
56
+ def validate_redirect_uri (redirect_uri : AnyHttpUrl | None , redirect_uris : list [AnyHttpUrl ]) -> AnyHttpUrl :
57
+ if not redirect_uris :
58
+ raise InvalidClientError ("Client has no registered redirect URIs" )
59
+
60
+ if redirect_uri is not None :
58
61
# Validate redirect_uri against client's registered redirect URIs
59
- if auth_request . redirect_uri not in client . redirect_uris :
62
+ if redirect_uri not in redirect_uris :
60
63
raise InvalidRequestError (
61
- f"Redirect URI '{ auth_request . redirect_uri } ' not registered for client"
64
+ f"Redirect URI '{ redirect_uri } ' not registered for client"
62
65
)
63
- return auth_request . redirect_uri
64
- elif len (client . redirect_uris ) == 1 :
65
- return client . redirect_uris [0 ]
66
+ return redirect_uri
67
+ elif len (redirect_uris ) == 1 :
68
+ return redirect_uris [0 ]
66
69
else :
67
70
raise InvalidRequestError ("redirect_uri must be specified when client has multiple registered URIs" )
68
71
@@ -104,8 +107,8 @@ async def authorization_handler(request: Request) -> Response:
104
107
105
108
106
109
# do validation which is dependent on the client configuration
107
- redirect_uri = validate_redirect_uri (auth_request , client )
108
- scopes = validate_scope (auth_request .scope , client )
110
+ redirect_uri = validate_redirect_uri (auth_request . redirect_uri , client . redirect_uris )
111
+ scopes = validate_scope (auth_request .scope , client . scope )
109
112
110
113
auth_params = AuthorizationParams (
111
114
state = auth_request .state ,
0 commit comments