@@ -82,6 +82,7 @@ These sections show how to use the SDK to perform permission and user management
828213 . [ Manage FGA (Fine-grained Authorization)] ( #manage-fga-fine-grained-authorization )
838314 . [ Manage Project] ( #manage-project )
848415 . [ Manage SSO Applications] ( #manage-sso-applications )
85+ 16 . [ Manage Outbound Applications] ( #manage-outbound-applications )
8586
8687If you wish to run any of our code samples and play with them, check out our [ Code Examples] ( #code-examples ) section.
8788
@@ -1310,6 +1311,169 @@ apps = apps_resp["apps"]
13101311 # Do something
13111312```
13121313
1314+ ### Manage Outbound Applications
1315+
1316+ You can create, update, delete, load outbound applications and fetch tokens for them:
1317+
1318+ ``` python
1319+ # Create a basic outbound application
1320+ response = descope_client.mgmt.outbound_application.create_application(
1321+ name = " my new app" ,
1322+ description = " my desc" ,
1323+ client_secret = " secret123" , # Optional
1324+ id = " my-custom-id" , # Optional
1325+ )
1326+ app_id = response[" app" ][" id" ]
1327+
1328+ # Create a full OAuth outbound application with all parameters
1329+ from descope.management.common import URLParam, AccessType, PromptType
1330+
1331+ # Create URL parameters for authorization
1332+ auth_params = [
1333+ URLParam(" response_type" , " code" ),
1334+ URLParam(" client_id" , " my-client-id" ),
1335+ URLParam(" redirect_uri" , " https://myapp.com/callback" )
1336+ ]
1337+
1338+ # Create URL parameters for token endpoint
1339+ token_params = [
1340+ URLParam(" grant_type" , " authorization_code" ),
1341+ URLParam(" client_id" , " my-client-id" )
1342+ ]
1343+
1344+ # Create prompt types
1345+ prompts = [PromptType.LOGIN , PromptType.CONSENT ]
1346+
1347+ full_app = descope_client.mgmt.outbound_application.create_application(
1348+ name = " My OAuth App" ,
1349+ description = " A full OAuth outbound application" ,
1350+ logo = " https://example.com/logo.png" ,
1351+ id = " my-custom-id" , # Optional custom ID
1352+ client_secret = " my-secret-key" ,
1353+ client_id = " my-client-id" ,
1354+ discovery_url = " https://accounts.google.com/.well-known/openid_configuration" ,
1355+ authorization_url = " https://accounts.google.com/o/oauth2/v2/auth" ,
1356+ authorization_url_params = auth_params,
1357+ token_url = " https://oauth2.googleapis.com/token" ,
1358+ token_url_params = token_params,
1359+ revocation_url = " https://oauth2.googleapis.com/revoke" ,
1360+ default_scopes = [" https://www.googleapis.com/auth/userinfo.profile" ],
1361+ default_redirect_url = " https://myapp.com/callback" ,
1362+ callback_domain = " myapp.com" ,
1363+ pkce = True , # Enable PKCE
1364+ access_type = AccessType.OFFLINE , # Request refresh tokens
1365+ prompt = prompts
1366+ )
1367+
1368+ # Update an outbound application with all parameters
1369+ # Update will override all fields as is. Use carefully.
1370+ descope_client.mgmt.outbound_application.update_application(
1371+ id = " my-app-id" ,
1372+ name = " my updated app" ,
1373+ description = " updated description" ,
1374+ logo = " https://example.com/logo.png" ,
1375+ client_secret = " new-secret" , # Optional
1376+ client_id = " new-client-id" ,
1377+ discovery_url = " https://accounts.google.com/.well-known/openid_configuration" ,
1378+ authorization_url = " https://accounts.google.com/o/oauth2/v2/auth" ,
1379+ authorization_url_params = auth_params,
1380+ token_url = " https://oauth2.googleapis.com/token" ,
1381+ token_url_params = token_params,
1382+ revocation_url = " https://oauth2.googleapis.com/revoke" ,
1383+ default_scopes = [" https://www.googleapis.com/auth/userinfo.profile" , " https://www.googleapis.com/auth/userinfo.email" ],
1384+ default_redirect_url = " https://myapp.com/updated-callback" ,
1385+ callback_domain = " myapp.com" ,
1386+ pkce = True ,
1387+ access_type = AccessType.OFFLINE ,
1388+ prompt = [PromptType.LOGIN , PromptType.CONSENT , PromptType.SELECT_ACCOUNT ]
1389+ )
1390+
1391+ # Delete an outbound application by id
1392+ # Outbound application deletion cannot be undone. Use carefully.
1393+ descope_client.mgmt.outbound_application.delete_application(" my-app-id" )
1394+
1395+ # Load an outbound application by id
1396+ app = descope_client.mgmt.outbound_application.load_application(" my-app-id" )
1397+
1398+ # Load all outbound applications
1399+ apps_resp = descope_client.mgmt.outbound_application.load_all_applications()
1400+ apps = apps_resp[" apps" ]
1401+ for app in apps:
1402+ # Do something with each app
1403+
1404+ # Fetch user token with specific scopes
1405+ user_token = descope_client.mgmt.outbound_application.fetch_token_by_scopes(
1406+ " my-app-id" ,
1407+ " user-id" ,
1408+ [" read" , " write" ],
1409+ {" refreshToken" : True }, # Optional
1410+ " tenant-id" # Optional
1411+ )
1412+
1413+ # Fetch latest user token
1414+ latest_user_token = descope_client.mgmt.outbound_application.fetch_token(
1415+ " my-app-id" ,
1416+ " user-id" ,
1417+ " tenant-id" , # Optional
1418+ {" forceRefresh" : True } # Optional
1419+ )
1420+
1421+ # Fetch tenant token with specific scopes
1422+ tenant_token = descope_client.mgmt.outbound_application.fetch_tenant_token_by_scopes(
1423+ " my-app-id" ,
1424+ " tenant-id" ,
1425+ [" read" , " write" ],
1426+ {" refreshToken" : True } # Optional
1427+ )
1428+
1429+ # Fetch latest tenant token
1430+ latest_tenant_token = descope_client.mgmt.outbound_application.fetch_tenant_token(
1431+ " my-app-id" ,
1432+ " tenant-id" ,
1433+ {" forceRefresh" : True } # Optional
1434+ )
1435+ ```
1436+
1437+ Fetch outbound application tokens using an inbound application token that includes the "outbound.token.fetch" scope (no management key required)
1438+
1439+ ``` python
1440+ # Fetch user token with specific scopes
1441+ user_token = descope_client.mgmt.outbound_application_by_token.fetch_token_by_scopes(
1442+ " inbound-app-token" ,
1443+ " my-app-id" ,
1444+ " user-id" ,
1445+ [" read" , " write" ],
1446+ {" refreshToken" : True }, # Optional
1447+ " tenant-id" # Optional
1448+ )
1449+
1450+ # Fetch latest user token
1451+ latest_user_token = descope_client.mgmt.outbound_application_by_token.fetch_token(
1452+ " inbound-app-token" ,
1453+ " my-app-id" ,
1454+ " user-id" ,
1455+ " tenant-id" , # Optional
1456+ {" forceRefresh" : True } # Optional
1457+ )
1458+
1459+ # Fetch tenant token with specific scopes
1460+ tenant_token = descope_client.mgmt.outbound_application_by_token.fetch_tenant_token_by_scopes(
1461+ " inbound-app-token" ,
1462+ " my-app-id" ,
1463+ " tenant-id" ,
1464+ [" read" , " write" ],
1465+ {" refreshToken" : True } # Optional
1466+ )
1467+
1468+ # Fetch latest tenant token
1469+ latest_tenant_token = descope_client.mgmt.outbound_application_by_token.fetch_tenant_token(
1470+ " inbound-app-token" ,
1471+ " my-app-id" ,
1472+ " tenant-id" ,
1473+ {" forceRefresh" : True } # Optional
1474+ )
1475+ ```
1476+
13131477### Utils for your end to end (e2e) tests and integration tests
13141478
13151479To ease your e2e tests, we exposed dedicated management methods,
0 commit comments