Skip to content

Commit 3ea23ce

Browse files
Dmitry SupranovichDmitry Supranovich
Dmitry Supranovich
authored and
Dmitry Supranovich
committed
Added client_id parameter to AssertionClient
Per https://datatracker.ietf.org/doc/html/rfc7521#section-4.1, client_id parameter, although optional, can still be passed when using assertions as authorization grants. Adding a way to pass that id to refresh token body.
1 parent 10cec25 commit 3ea23ce

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

authlib/integrations/httpx_client/assertion_client.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AsyncAssertionClient(_AssertionClient, AsyncClient):
1717
DEFAULT_GRANT_TYPE = JWT_BEARER_GRANT_TYPE
1818

1919
def __init__(self, token_endpoint, issuer, subject, audience=None, grant_type=None,
20-
claims=None, token_placement='header', scope=None, **kwargs):
20+
claims=None, token_placement='header', scope=None, client_id=None, **kwargs):
2121

2222
client_kwargs = extract_client_kwargs(kwargs)
2323
AsyncClient.__init__(self, **client_kwargs)
@@ -26,7 +26,7 @@ def __init__(self, token_endpoint, issuer, subject, audience=None, grant_type=No
2626
self, session=None,
2727
token_endpoint=token_endpoint, issuer=issuer, subject=subject,
2828
audience=audience, grant_type=grant_type, claims=claims,
29-
token_placement=token_placement, scope=scope, **kwargs
29+
token_placement=token_placement, scope=scope, client_id=None, **kwargs
3030
)
3131

3232
async def request(self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAULT, **kwargs):
@@ -62,7 +62,7 @@ class AssertionClient(_AssertionClient, Client):
6262
DEFAULT_GRANT_TYPE = JWT_BEARER_GRANT_TYPE
6363

6464
def __init__(self, token_endpoint, issuer, subject, audience=None, grant_type=None,
65-
claims=None, token_placement='header', scope=None, **kwargs):
65+
claims=None, token_placement='header', scope=None, client_id=None, **kwargs):
6666

6767
client_kwargs = extract_client_kwargs(kwargs)
6868
Client.__init__(self, **client_kwargs)
@@ -71,7 +71,7 @@ def __init__(self, token_endpoint, issuer, subject, audience=None, grant_type=No
7171
self, session=self,
7272
token_endpoint=token_endpoint, issuer=issuer, subject=subject,
7373
audience=audience, grant_type=grant_type, claims=claims,
74-
token_placement=token_placement, scope=scope, **kwargs
74+
token_placement=token_placement, scope=scope, client_id=None, **kwargs
7575
)
7676

7777
def request(self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAULT, **kwargs):

authlib/integrations/requests_client/assertion_session.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class AssertionSession(AssertionClient, Session):
2525
DEFAULT_GRANT_TYPE = JWT_BEARER_GRANT_TYPE
2626

2727
def __init__(self, token_endpoint, issuer, subject, audience=None, grant_type=None,
28-
claims=None, token_placement='header', scope=None, **kwargs):
28+
claims=None, token_placement='header', scope=None, client_id=None, **kwargs):
2929
Session.__init__(self)
3030
update_session_configure(self, kwargs)
3131
AssertionClient.__init__(
3232
self, session=self,
3333
token_endpoint=token_endpoint, issuer=issuer, subject=subject,
3434
audience=audience, grant_type=grant_type, claims=claims,
35-
token_placement=token_placement, scope=scope, **kwargs
35+
token_placement=token_placement, scope=scope, client_id=None, **kwargs
3636
)
3737

3838
def request(self, method, url, withhold_token=False, auth=None, **kwargs):

authlib/oauth2/rfc7521/client.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AssertionClient(object):
1414

1515
def __init__(self, session, token_endpoint, issuer, subject,
1616
audience=None, grant_type=None, claims=None,
17-
token_placement='header', scope=None, **kwargs):
17+
token_placement='header', scope=None, client_id=None, **kwargs):
1818

1919
self.session = session
2020

@@ -34,6 +34,7 @@ def __init__(self, session, token_endpoint, issuer, subject,
3434
self.audience = audience
3535
self.claims = claims
3636
self.scope = scope
37+
self.client_id = client_id
3738
if self.token_auth_class is not None:
3839
self.token_auth = self.token_auth_class(None, token_placement, self)
3940
self._kwargs = kwargs
@@ -66,6 +67,8 @@ def refresh_token(self):
6667
}
6768
if self.scope:
6869
data['scope'] = self.scope
70+
if self.client_id:
71+
data['client_id'] = self.client_id
6972

7073
return self._refresh_token(data)
7174

tests/clients/test_httpx/test_assertion_client.py

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def verifier(request):
4242
header={'alg': 'HS256'},
4343
key='secret',
4444
scope='email',
45+
client_id='client',
4546
claims={'test_mode': 'true'},
4647
app=MockDispatch(default_token, assert_func=verifier)
4748
) as client:

tests/clients/test_httpx/test_async_assertion_client.py

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ async def verifier(request):
4444
header={'alg': 'HS256'},
4545
key='secret',
4646
scope='email',
47+
client_id='client',
4748
claims={'test_mode': 'true'},
4849
app=AsyncMockDispatch(default_token, assert_func=verifier)
4950
) as client:

0 commit comments

Comments
 (0)