Skip to content

Commit db94c12

Browse files
handle opt args better, fix linting
1 parent d66def5 commit db94c12

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

python/delta_sharing/_internal_auth.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ def __init__(
198198
self.key_id = key_id
199199
self.private_key = private_key
200200
self.issuer = issuer
201-
self.resource = resource
202201
self.scope = scope
202+
self.resource = resource
203203
if algorithm is None:
204204
algorithm = "RS256"
205205
self.algorithm = algorithm
@@ -210,12 +210,14 @@ def client_credentials(self) -> OAuthClientCredentials:
210210
jwt_claims = {
211211
"aud": self.issuer,
212212
"iss": self.client_id,
213-
"scope": self.scope,
214-
"resource": self.resource, # In OAuth 2 spec audience is called resource
215213
"iat": timestamp,
216214
"exp": timestamp + 120,
217215
"jti": str(uuid.uuid4()),
218216
}
217+
if self.scope:
218+
jwt_claims["scope"] = self.scope
219+
if self.resource:
220+
jwt_claims["resource"] = self.resource # In OAuth 2 spec audience is called resource
219221
signed_jwt = self._signed_jwt(jwt_header, jwt_claims)
220222
body = {
221223
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",

python/delta_sharing/tests/test_oauth_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ def test_oauth_client_should_handle_401_unauthorized_response(mock_server):
111111
"pk-test-access-token",
112112
),
113113
(
114-
'{"access_token": "pk-test-access-token", "expires_in": "3600", "token_type": "bearer"}',
114+
(
115+
'{"access_token": "pk-test-access-token", "expires_in": "3600", '
116+
'"token_type": "bearer"}'
117+
),
115118
3600,
116119
"pk-test-access-token",
117120
),
@@ -152,8 +155,6 @@ def test_private_key_oauth_client_should_parse_token_response_correctly(
152155
assert claims_arg.get("scope") == "scope"
153156

154157

155-
# @mock.patch("_internal_auth.PrivateKeyOAuthClient._signed_jwt", return_value="signed-jwt-dummy-val")
156-
# @mock.patch("PrivateKeyOAuthClient._signed_jwt", return_value="signed-jwt-dummy-val")
157158
def test_private_key_oauth_client_should_handle_401_unauthorized_response(mock_server):
158159

159160
with patch.object(PrivateKeyOAuthClient, "_signed_jwt") as _signed_jwt_mock:

0 commit comments

Comments
 (0)