Skip to content

Commit 4ee8811

Browse files
new optional tenant id param added (breaking)
1 parent c9522ad commit 4ee8811

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

src/main/python/fusionauth/fusionauth_client.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def add_user_to_family(self, family_id, request):
7676
.put() \
7777
.go()
7878

79-
def approve_device(self, token, user_code, client_id=None, client_secret=None):
79+
def approve_device(self, token, user_code, client_id=None, client_secret=None, tenant_id=None):
8080
"""
8181
Approve a device grant.
8282
@@ -85,12 +85,14 @@ def approve_device(self, token, user_code, client_id=None, client_secret=None):
8585
client_secret: (Optional) The client secret. This value will be required if client authentication is enabled.
8686
token: The access token used to identify the user.
8787
user_code: The end-user verification code.
88+
tenant_id: (Optional) The Id of the tenant to use for this request.
8889
"""
8990
body = {
9091
"client_id": client_id,
9192
"client_secret": client_secret,
9293
"token": token,
9394
"user_code": user_code,
95+
"tenantId": tenantId,
9496
}
9597
return self.start().uri('/oauth2/device/approve') \
9698
.body_handler(FormDataBodyHandler(body)) \
@@ -226,7 +228,7 @@ def check_change_password_using_login_id(self, login_id):
226228
.get() \
227229
.go()
228230

229-
def client_credentials_grant(self, client_id=None, client_secret=None, scope=None):
231+
def client_credentials_grant(self, client_id=None, client_secret=None, scope=None, tenant_id=None):
230232
"""
231233
Make a Client Credentials grant request to obtain an access token.
232234
@@ -236,12 +238,14 @@ def client_credentials_grant(self, client_id=None, client_secret=None, scope=Non
236238
client_secret: (Optional) The client secret used to authenticate this request.
237239
This parameter is optional when Basic Authorization is used to authenticate this request.
238240
scope: (Optional) This parameter is used to indicate which target entity you are requesting access. To request access to an entity, use the format target-entity:<target-entity-id>:<roles>. Roles are an optional comma separated list.
241+
tenant_id: (Optional) The Id of the tenant to use for this request.
239242
"""
240243
body = {
241244
"client_id": client_id,
242245
"client_secret": client_secret,
243246
"grant_type": "client_credentials",
244247
"scope": scope,
248+
"tenantId": tenantId,
245249
}
246250
return self.start_anonymous().uri('/oauth2/token') \
247251
.body_handler(FormDataBodyHandler(body)) \
@@ -1333,7 +1337,7 @@ def enable_two_factor(self, user_id, request):
13331337
.post() \
13341338
.go()
13351339

1336-
def exchange_o_auth_code_for_access_token(self, code, redirect_uri, client_id=None, client_secret=None):
1340+
def exchange_o_auth_code_for_access_token(self, code, redirect_uri, client_id=None, client_secret=None, tenant_id=None):
13371341
"""
13381342
Exchanges an OAuth authorization code for an access token.
13391343
Makes a request to the Token endpoint to exchange the authorization code returned from the Authorize endpoint for an access token.
@@ -1344,20 +1348,22 @@ def exchange_o_auth_code_for_access_token(self, code, redirect_uri, client_id=No
13441348
This parameter is optional when Basic Authorization is used to authenticate this request.
13451349
client_secret: (Optional) The client secret. This value will be required if client authentication is enabled.
13461350
redirect_uri: The URI to redirect to upon a successful request.
1351+
tenant_id: (Optional) The Id of the tenant to use for this request.
13471352
"""
13481353
body = {
13491354
"code": code,
13501355
"client_id": client_id,
13511356
"client_secret": client_secret,
13521357
"grant_type": "authorization_code",
13531358
"redirect_uri": redirect_uri,
1359+
"tenantId": tenantId,
13541360
}
13551361
return self.start_anonymous().uri('/oauth2/token') \
13561362
.body_handler(FormDataBodyHandler(body)) \
13571363
.post() \
13581364
.go()
13591365

1360-
def exchange_o_auth_code_for_access_token_using_pkce(self, code, redirect_uri, code_verifier, client_id=None, client_secret=None):
1366+
def exchange_o_auth_code_for_access_token_using_pkce(self, code, redirect_uri, code_verifier, client_id=None, client_secret=None, tenant_id=None):
13611367
"""
13621368
Exchanges an OAuth authorization code and code_verifier for an access token.
13631369
Makes a request to the Token endpoint to exchange the authorization code returned from the Authorize endpoint and a code_verifier for an access token.
@@ -1369,6 +1375,7 @@ def exchange_o_auth_code_for_access_token_using_pkce(self, code, redirect_uri, c
13691375
client_secret: (Optional) The client secret. This value may optionally be provided in the request body instead of the Authorization header.
13701376
redirect_uri: The URI to redirect to upon a successful request.
13711377
code_verifier: The random string generated previously. Will be compared with the code_challenge sent previously, which allows the OAuth provider to authenticate your app.
1378+
tenant_id: (Optional) The Id of the tenant to use for this request.
13721379
"""
13731380
body = {
13741381
"code": code,
@@ -1377,13 +1384,14 @@ def exchange_o_auth_code_for_access_token_using_pkce(self, code, redirect_uri, c
13771384
"grant_type": "authorization_code",
13781385
"redirect_uri": redirect_uri,
13791386
"code_verifier": code_verifier,
1387+
"tenantId": tenantId,
13801388
}
13811389
return self.start_anonymous().uri('/oauth2/token') \
13821390
.body_handler(FormDataBodyHandler(body)) \
13831391
.post() \
13841392
.go()
13851393

1386-
def exchange_refresh_token_for_access_token(self, refresh_token, client_id=None, client_secret=None, scope=None, user_code=None):
1394+
def exchange_refresh_token_for_access_token(self, refresh_token, client_id=None, client_secret=None, scope=None, user_code=None, tenant_id=None):
13871395
"""
13881396
Exchange a Refresh Token for an Access Token.
13891397
If you will be using the Refresh Token Grant, you will make a request to the Token endpoint to exchange the user’s refresh token for an access token.
@@ -1395,6 +1403,7 @@ def exchange_refresh_token_for_access_token(self, refresh_token, client_id=None,
13951403
client_secret: (Optional) The client secret. This value may optionally be provided in the request body instead of the Authorization header.
13961404
scope: (Optional) This parameter is optional and if omitted, the same scope requested during the authorization request will be used. If provided the scopes must match those requested during the initial authorization request.
13971405
user_code: (Optional) The end-user verification code. This code is required if using this endpoint to approve the Device Authorization.
1406+
tenant_id: (Optional) The Id of the tenant to use for this request. Required if the request is for a universal application.
13981407
"""
13991408
body = {
14001409
"refresh_token": refresh_token,
@@ -1403,6 +1412,7 @@ def exchange_refresh_token_for_access_token(self, refresh_token, client_id=None,
14031412
"grant_type": "refresh_token",
14041413
"scope": scope,
14051414
"user_code": user_code,
1415+
"tenantId": tenantId,
14061416
}
14071417
return self.start_anonymous().uri('/oauth2/token') \
14081418
.body_handler(FormDataBodyHandler(body)) \
@@ -1421,7 +1431,7 @@ def exchange_refresh_token_for_jwt(self, request):
14211431
.post() \
14221432
.go()
14231433

1424-
def exchange_user_credentials_for_access_token(self, username, password, client_id=None, client_secret=None, scope=None, user_code=None):
1434+
def exchange_user_credentials_for_access_token(self, username, password, client_id=None, client_secret=None, scope=None, user_code=None, tenant_id=None):
14251435
"""
14261436
Exchange User Credentials for a Token.
14271437
If you will be using the Resource Owner Password Credential Grant, you will make a request to the Token endpoint to exchange the user’s email and password for an access token.
@@ -1434,6 +1444,7 @@ def exchange_user_credentials_for_access_token(self, username, password, client_
14341444
client_secret: (Optional) The client secret. This value may optionally be provided in the request body instead of the Authorization header.
14351445
scope: (Optional) This parameter is optional and if omitted, the same scope requested during the authorization request will be used. If provided the scopes must match those requested during the initial authorization request.
14361446
user_code: (Optional) The end-user verification code. This code is required if using this endpoint to approve the Device Authorization.
1447+
tenant_id: (Optional) The Id of the tenant to use for this request.
14371448
"""
14381449
body = {
14391450
"username": username,
@@ -1443,6 +1454,7 @@ def exchange_user_credentials_for_access_token(self, username, password, client_
14431454
"grant_type": "password",
14441455
"scope": scope,
14451456
"user_code": user_code,
1457+
"tenantId": tenantId,
14461458
}
14471459
return self.start_anonymous().uri('/oauth2/token') \
14481460
.body_handler(FormDataBodyHandler(body)) \
@@ -1621,32 +1633,36 @@ def import_web_authn_credential(self, request):
16211633
.post() \
16221634
.go()
16231635

1624-
def introspect_access_token(self, client_id, token):
1636+
def introspect_access_token(self, client_id, token, tenant_id=None):
16251637
"""
16261638
Inspect an access token issued as the result of the User based grant such as the Authorization Code Grant, Implicit Grant, the User Credentials Grant or the Refresh Grant.
16271639
16281640
Attributes:
16291641
client_id: The unique client identifier. The client Id is the Id of the FusionAuth Application for which this token was generated.
16301642
token: The access token returned by this OAuth provider as the result of a successful client credentials grant.
1643+
tenant_id: (Optional) The Id of the tenant to use for this request.
16311644
"""
16321645
body = {
16331646
"client_id": client_id,
16341647
"token": token,
1648+
"tenantId": tenantId,
16351649
}
16361650
return self.start_anonymous().uri('/oauth2/introspect') \
16371651
.body_handler(FormDataBodyHandler(body)) \
16381652
.post() \
16391653
.go()
16401654

1641-
def introspect_client_credentials_access_token(self, token):
1655+
def introspect_client_credentials_access_token(self, token, tenant_id=None):
16421656
"""
16431657
Inspect an access token issued as the result of the Client Credentials Grant.
16441658
16451659
Attributes:
16461660
token: The access token returned by this OAuth provider as the result of a successful client credentials grant.
1661+
tenant_id: (Optional) The Id of the tenant to use for this request.
16471662
"""
16481663
body = {
16491664
"token": token,
1665+
"tenantId": tenantId,
16501666
}
16511667
return self.start_anonymous().uri('/oauth2/introspect') \
16521668
.body_handler(FormDataBodyHandler(body)) \
@@ -3451,7 +3467,7 @@ def retrieve_user_by_verification_id(self, verification_id):
34513467
.get() \
34523468
.go()
34533469

3454-
def retrieve_user_code(self, client_id, client_secret, user_code):
3470+
def retrieve_user_code(self, client_id, client_secret, user_code, tenant_id=None):
34553471
"""
34563472
Retrieve a user_code that is part of an in-progress Device Authorization Grant.
34573473
@@ -3461,18 +3477,20 @@ def retrieve_user_code(self, client_id, client_secret, user_code):
34613477
client_id: The client Id.
34623478
client_secret: The client Id.
34633479
user_code: The end-user verification code.
3480+
tenant_id: (Optional) The Id of the tenant to use for this request.
34643481
"""
34653482
body = {
34663483
"client_id": client_id,
34673484
"client_secret": client_secret,
34683485
"user_code": user_code,
34693486
}
34703487
return self.start_anonymous().uri('/oauth2/device/user-code') \
3488+
.url_parameter('tenantId', self.convert_true_false(tenant_id)) \
34713489
.body_handler(FormDataBodyHandler(body)) \
34723490
.get() \
34733491
.go()
34743492

3475-
def retrieve_user_code_using_api_key(self, user_code):
3493+
def retrieve_user_code_using_api_key(self, user_code, tenant_id=None):
34763494
"""
34773495
Retrieve a user_code that is part of an in-progress Device Authorization Grant.
34783496
@@ -3482,11 +3500,13 @@ def retrieve_user_code_using_api_key(self, user_code):
34823500
34833501
Attributes:
34843502
user_code: The end-user verification code.
3503+
tenant_id: (Optional) The Id of the tenant to use for this request.
34853504
"""
34863505
body = {
34873506
"user_code": user_code,
34883507
}
34893508
return self.start_anonymous().uri('/oauth2/device/user-code') \
3509+
.url_parameter('tenantId', self.convert_true_false(tenant_id)) \
34903510
.body_handler(FormDataBodyHandler(body)) \
34913511
.get() \
34923512
.go()
@@ -3527,15 +3547,17 @@ def retrieve_user_consents(self, user_id):
35273547
.get() \
35283548
.go()
35293549

3530-
def retrieve_user_info_from_access_token(self, encoded_jwt):
3550+
def retrieve_user_info_from_access_token(self, encoded_jwt, tenant_id=None):
35313551
"""
35323552
Call the UserInfo endpoint to retrieve User Claims from the access token issued by FusionAuth.
35333553
35343554
Attributes:
35353555
encoded_jwt: The encoded JWT (access token).
3556+
tenant_id: (Optional) The Id of the tenant to use for this request.
35363557
"""
35373558
return self.start_anonymous().uri('/oauth2/userinfo') \
35383559
.authorization("Bearer " + encoded_jwt) \
3560+
.url_parameter('tenantId', self.convert_true_false(tenant_id)) \
35393561
.get() \
35403562
.go()
35413563

@@ -4813,18 +4835,20 @@ def upsert_entity_grant(self, entity_id, request):
48134835
.post() \
48144836
.go()
48154837

4816-
def validate_device(self, user_code, client_id):
4838+
def validate_device(self, user_code, client_id, tenant_id=None):
48174839
"""
48184840
Validates the end-user provided user_code from the user-interaction of the Device Authorization Grant.
48194841
If you build your own activation form you should validate the user provided code prior to beginning the Authorization grant.
48204842
48214843
Attributes:
48224844
user_code: The end-user verification code.
48234845
client_id: The client Id.
4846+
tenant_id: (Optional) The Id of the tenant to use for this request.
48244847
"""
48254848
return self.start_anonymous().uri('/oauth2/device/validate') \
48264849
.url_parameter('user_code', self.convert_true_false(user_code)) \
48274850
.url_parameter('client_id', self.convert_true_false(client_id)) \
4851+
.url_parameter('tenantId', self.convert_true_false(tenant_id)) \
48284852
.get() \
48294853
.go()
48304854

0 commit comments

Comments
 (0)