Skip to content

Commit dd36b80

Browse files
committed
Add validation for authorization_params and requested_expiry
1 parent a305ab3 commit dd36b80

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/auth0_server_python/auth_server/server_client.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,22 @@ async def initiate_backchannel_authentication(
936936
"login_hint.sub"
937937
)
938938

939+
authorization_params = options.get('authorization_params')
940+
if authorization_params is not None and not isinstance(authorization_params, dict):
941+
raise ApiError(
942+
"invalid_argument",
943+
"authorization_params must be a dict"
944+
)
945+
946+
if authorization_params:
947+
requested_expiry = authorization_params.get("requested_expiry")
948+
if requested_expiry is not None:
949+
if not isinstance(requested_expiry, int) or requested_expiry <= 0:
950+
raise ApiError(
951+
"invalid_argument",
952+
"authorization_params.requested_expiry must be a positive integer"
953+
)
954+
939955
try:
940956
# Fetch OpenID Connect metadata if not already fetched
941957
if not hasattr(self, '_oauth_metadata'):
@@ -976,8 +992,8 @@ async def initiate_backchannel_authentication(
976992
if self._default_authorization_params:
977993
params.update(self._default_authorization_params)
978994

979-
if options.get('authorization_params'):
980-
params.update(options.get('authorization_params'))
995+
if authorization_params:
996+
params.update(authorization_params)
981997

982998
# Make the backchannel authentication request
983999
async with httpx.AsyncClient() as client:

src/auth0_server_python/tests/test_server_client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,26 @@ async def test_initiate_backchannel_authentication_error_response(mocker):
982982
await client.initiate_backchannel_authentication({"login_hint": {"sub": "user123"}})
983983
assert "Bad request" in str(exc.value)
984984

985+
@pytest.mark.asyncio
986+
async def test_authorization_params_not_dict_raises():
987+
client = ServerClient("domain", "client_id", "client_secret", secret="s")
988+
with pytest.raises(ApiError) as exc:
989+
await client.initiate_backchannel_authentication({
990+
"login_hint": {"sub": "user_id"},
991+
"authorization_params": "not_a_dict"
992+
})
993+
assert "authorization_params must be a dict" in str(exc.value)
994+
995+
@pytest.mark.asyncio
996+
async def test_requested_expiry_not_positive_int_raises():
997+
client = ServerClient("domain", "client_id", "client_secret", secret="s")
998+
with pytest.raises(ApiError) as exc:
999+
await client.initiate_backchannel_authentication({
1000+
"login_hint": {"sub": "user_id"},
1001+
"authorization_params": {"requested_expiry": -10}
1002+
})
1003+
assert "requested_expiry must be a positive integer" in str(exc.value)
1004+
9851005
@pytest.mark.asyncio
9861006
async def test_backchannel_authentication_grant_success(mocker):
9871007
client = ServerClient(

0 commit comments

Comments
 (0)