Skip to content

Commit 2ea4a36

Browse files
committed
Adjusting API to make server_configuration a required parameter
1 parent 114d1bb commit 2ea4a36

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

oauth2cli/oauth2.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,26 @@ class BaseClient(object):
2020
# More on Client Types at https://tools.ietf.org/html/rfc6749#section-2.1
2121
def __init__(
2222
self,
23+
server_configuration, # type: dict
2324
client_id, # type: str
2425
client_secret=None, # type: Optional[str]
2526
client_assertion=None, # type: Optional[str]
2627
client_assertion_type=None, # type: Optional[str]
2728
default_body=None, # type: Optional[dict]
28-
configuration=None, # type: Optional[dict]
2929
):
3030
"""Initialize a client object to talk all the OAuth2 grants to the server.
3131
3232
Args:
33-
client_id (str): The client's id
33+
server_configuration (dict):
34+
It contains the configuration (i.e. metadata) of the auth server.
35+
The actual content typically contains keys like
36+
"authorization_endpoint", "token_endpoint", etc..
37+
Based on RFC 8414 (https://tools.ietf.org/html/rfc8414),
38+
you can probably fetch it online from either
39+
https://example.com/.../.well-known/oauth-authorization-server
40+
or
41+
https://example.com/.../.well-known/openid-configuration
42+
client_id (str): The client's id, issued by the authorization server
3443
client_secret (str): Triggers HTTP AUTH for Confidential Client
3544
client_assertion (str):
3645
The client assertion to authenticate this client, per RFC 7521.
@@ -45,16 +54,8 @@ def __init__(
4554
you could choose to set this as {"client_secret": "your secret"}
4655
if your authorization server wants it to be in the request body
4756
(rather than in the request header).
48-
configuration (dict):
49-
It contains the configuration (i.e. metadata) of the auth server.
50-
The actual content typically contains keys like
51-
"authorization_endpoint", "token_endpoint", etc..
52-
Based on RFC 8414 (https://tools.ietf.org/html/rfc8414),
53-
you can probably fetch it online from either
54-
https://example.com/.../.well-known/oauth-authorization-server
55-
or
56-
https://example.com/.../.well-known/openid-configuration
5757
"""
58+
self.configuration = server_configuration
5859
self.client_id = client_id
5960
self.client_secret = client_secret
6061
self.default_body = default_body or {}
@@ -65,7 +66,6 @@ def __init__(
6566
client_assertion_type = TYPE_JWT if "." in client_assertion else TYPE_SAML2
6667
self.default_body["client_assertion"] = client_assertion
6768
self.default_body["client_assertion_type"] = client_assertion_type
68-
self.configuration = configuration or {}
6969
self.logger = logging.getLogger(__name__)
7070

7171
def _build_auth_request_params(self, response_type, **kwargs):
@@ -311,12 +311,12 @@ class initialization.
311311
return self._obtain_token("client_credentials", data=data, **kwargs)
312312

313313
def __init__(self,
314-
client_id,
314+
server_configuration, client_id,
315315
on_obtaining_tokens=lambda event: None, # event is defined in _obtain_token(...)
316316
on_removing_rt=lambda token_item: None,
317317
on_updating_rt=lambda token_item, new_rt: None,
318318
**kwargs):
319-
super(Client, self).__init__(client_id, **kwargs)
319+
super(Client, self).__init__(server_configuration, client_id, **kwargs)
320320
self.on_obtaining_tokens = on_obtaining_tokens
321321
self.on_removing_rt = on_removing_rt
322322
self.on_updating_rt = on_updating_rt

tests/test_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def setUpClass(cls):
8484
with open(os.path.join(THIS_FOLDER, private_key_path)) as f:
8585
private_key = f.read() # Expecting PEM format
8686
cls.client = Client(
87+
CONFIG["openid_configuration"],
8788
CONFIG['client_id'],
8889
client_assertion=JwtSigner(
8990
private_key,
@@ -93,12 +94,11 @@ def setUpClass(cls):
9394
audience=CONFIG["openid_configuration"]["token_endpoint"],
9495
issuer=CONFIG["client_id"],
9596
),
96-
configuration=CONFIG["openid_configuration"])
97+
)
9798
else:
9899
cls.client = Client(
99-
CONFIG['client_id'],
100-
client_secret=CONFIG.get('client_secret'),
101-
configuration=CONFIG["openid_configuration"])
100+
CONFIG["openid_configuration"], CONFIG['client_id'],
101+
client_secret=CONFIG.get('client_secret'))
102102

103103
@unittest.skipUnless("client_secret" in CONFIG, "client_secret missing")
104104
def test_client_credentials(self):

0 commit comments

Comments
 (0)