Skip to content

Commit 595dcde

Browse files
committed
Merge branch 'adjust-api-signatures' into dev
2 parents dd1c283 + ac99ccb commit 595dcde

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

oauth2cli/oauth2.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def _obtain_token( # The verb "obtain" is influenced by OAUTH2 RFC 6749
133133
"Token response is not in json format: %s", resp.text)
134134
raise
135135

136-
def obtain_token_with_refresh_token(self, refresh_token, scope=None, **kwargs):
136+
def obtain_token_by_refresh_token(self, refresh_token, scope=None, **kwargs):
137137
"""Obtain an access token via a refresh token.
138138
139139
:param refresh_token: The refresh token issued to the client
@@ -278,7 +278,7 @@ def parse_auth_response(params, state=None):
278278
raise ValueError('state mismatch')
279279
return params
280280

281-
def obtain_token_with_authorization_code(
281+
def obtain_token_by_authorization_code(
282282
self, code, redirect_uri=None, **kwargs):
283283
"""Get a token via auhtorization code. a.k.a. Authorization Code Grant.
284284
@@ -299,18 +299,20 @@ def obtain_token_with_authorization_code(
299299
data["client_id"] = self.client_id
300300
return self._obtain_token("authorization_code", data=data, **kwargs)
301301

302-
def obtain_token_with_username_password(
302+
def obtain_token_by_username_password(
303303
self, username, password, scope=None, **kwargs):
304304
"""The Resource Owner Password Credentials Grant, used by legacy app."""
305305
data = kwargs.pop("data", {})
306306
data.update(username=username, password=password, scope=scope)
307307
return self._obtain_token("password", data=data, **kwargs)
308308

309-
def obtain_token_with_client_credentials(self, scope=None, **kwargs):
310-
"""Get token by client credentials. a.k.a. Client Credentials Grant,
311-
used by Backend Applications.
309+
def obtain_token_for_client(self, scope=None, **kwargs):
310+
"""Obtain token for this client (rather than for an end user),
311+
a.k.a. the Client Credentials Grant, used by Backend Applications.
312312
313-
You may want to explicitly provide an optional client_secret parameter,
313+
We don't name it obtain_token_by_client_credentials(...) because those
314+
credentials are typically already provided in class constructor, not here.
315+
You can still explicitly provide an optional client_secret parameter,
314316
or you can provide such extra parameters as `default_body` during the
315317
class initialization.
316318
"""
@@ -352,7 +354,7 @@ def _obtain_token(self, grant_type, params=None, data=None, *args, **kwargs):
352354
})
353355
return resp
354356

355-
def obtain_token_with_refresh_token(self, token_item, scope=None,
357+
def obtain_token_by_refresh_token(self, token_item, scope=None,
356358
rt_getter=lambda token_item: token_item["refresh_token"],
357359
**kwargs):
358360
# type: (Union[str, dict], Union[str, list, set, tuple], Callable) -> dict
@@ -367,10 +369,10 @@ def obtain_token_with_refresh_token(self, token_item, scope=None,
367369
"""
368370
if isinstance(token_item, str):
369371
# Satisfy the L of SOLID, although we expect caller uses a dict
370-
return super(Client, self).obtain_token_with_refresh_token(
372+
return super(Client, self).obtain_token_by_refresh_token(
371373
token_item, scope=scope, **kwargs)
372374
if isinstance(token_item, dict):
373-
resp = super(Client, self).obtain_token_with_refresh_token(
375+
resp = super(Client, self).obtain_token_by_refresh_token(
374376
rt_getter(token_item), scope=scope, **kwargs)
375377
if resp.get('error') == 'invalid_grant':
376378
self.on_removing_rt(token_item) # Discard old RT
@@ -379,7 +381,7 @@ def obtain_token_with_refresh_token(self, token_item, scope=None,
379381
return resp
380382
raise ValueError("token_item should not be a type %s" % type(token_item))
381383

382-
def obtain_token_with_assertion(
384+
def obtain_token_by_assertion(
383385
self, assertion, grant_type=None, scope=None, **kwargs):
384386
# type: (str, Union[str, None], Union[str, list, set, tuple]) -> dict
385387
"""This method implements Assertion Framework for OAuth2 (RFC 7521).

tests/test_client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,13 @@ def setUpClass(cls):
102102

103103
@unittest.skipUnless("client_secret" in CONFIG, "client_secret missing")
104104
def test_client_credentials(self):
105-
result = self.client.obtain_token_with_client_credentials(
106-
CONFIG.get('scope'))
105+
result = self.client.obtain_token_for_client(CONFIG.get('scope'))
107106
self.assertIn('access_token', result)
108107

109108
@unittest.skipUnless(
110109
"username" in CONFIG and "password" in CONFIG, "username/password missing")
111110
def test_username_password(self):
112-
result = self.client.obtain_token_with_username_password(
111+
result = self.client.obtain_token_by_username_password(
113112
CONFIG["username"], CONFIG["password"],
114113
data={"resource": CONFIG.get("resource")}, # MSFT AAD V1 only
115114
scope=CONFIG.get("scope"))
@@ -125,7 +124,7 @@ def test_auth_code(self):
125124
"code", redirect_uri=redirect_uri, scope=CONFIG.get("scope"))
126125
ac = obtain_auth_code(port, auth_uri=auth_request_uri)
127126
self.assertNotEqual(ac, None)
128-
result = self.client.obtain_token_with_authorization_code(
127+
result = self.client.obtain_token_by_authorization_code(
129128
ac,
130129
data={
131130
"scope": CONFIG.get("scope"),

0 commit comments

Comments
 (0)