### Update User with Okta Python SDK Source: https://github.com/okta/okta-sdk-python/blob/master/docs/UserApi.md Demonstrates how to update a user's information using the `update_user` function from the Okta Python SDK. This example shows the setup for API key or OAuth authentication and how to handle the API response or exceptions. It requires the `okta` library and specific model classes like `UpdateUserRequest` and `User`. ```python import okta from okta.models.update_user_request import UpdateUserRequest from okta.models.user import User from okta.rest import ApiException from pprint import pprint import os # Defining the host is optional and defaults to https://subdomain.okta.com # See configuration.py for a list of all supported configuration parameters. configuration = okta.Configuration( host = "https://subdomain.okta.com" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure API key authorization: apiToken configuration.api_key['apiToken'] = os.environ["API_KEY"] # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed # configuration.api_key_prefix['apiToken'] = 'Bearer' configuration.access_token = os.environ["ACCESS_TOKEN"] # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.UserApi(api_client) user_id = 'user_id_example' # str | user = okta.UpdateUserRequest() # UpdateUserRequest | strict = True # bool | (optional) try: # Update a User api_response = api_instance.update_user(user_id, user, strict=strict) print("The response of UserApi->update_user:\n") pprint(api_response) except Exception as e: print("Exception when calling UserApi->update_user: %s\n" % e) ``` -------------------------------- ### List Assigned Application Links - Python Source: https://github.com/okta/okta-sdk-python/blob/master/docs/UserApi.md This code example shows how to list all application links assigned to a user using the Okta SDK for Python. It follows the same authentication and client configuration pattern as other examples and utilizes the `list_app_links` method, requiring only the user ID as a parameter. The response is a list of `AppLink` objects. ```python import okta from okta.models.app_link import AppLink from okta.rest import ApiException from pprint import pprint import os # Defining the host is optional and defaults to https://subdomain.okta.com # See configuration.py for a list of all supported configuration parameters. configuration = okta.Configuration( host = "https://subdomain.okta.com" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure API key authorization: apiToken configuration.api_key['apiToken'] = os.environ["API_KEY"] # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed # configuration.api_key_prefix['apiToken'] = 'Bearer' configuration.access_token = os.environ["ACCESS_TOKEN"] # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.UserApi(api_client) user_id = 'user_id_example' # str | try: # List all Assigned Application Links api_response = api_instance.list_app_links(user_id) print("The response of UserApi->list_app_links:\n") pprint(api_response) except Exception as e: print("Exception when calling UserApi->list_app_links: %s\n" % e) ``` -------------------------------- ### Python: Okta Subscription Model Usage Source: https://github.com/okta/okta-sdk-python/blob/master/docs/Subscription.md Demonstrates how to create and manipulate Subscription objects in Python using the Okta SDK. This includes instantiation from JSON, conversion to a dictionary, and vice-versa. Ensure the Okta SDK is installed (`pip install okta`). ```python from okta.models.subscription import Subscription # TODO update the JSON string below json_string = "{}" # create an instance of Subscription from a JSON string subscription_instance = Subscription.from_json(json_string) # print the JSON string representation of the object print(Subscription.to_json()) # convert the object into a dict subscription_dict = subscription_instance.to_dict() # create an instance of Subscription from a dict subscription_from_dict = Subscription.from_dict(subscription_dict) ``` -------------------------------- ### Delete Authorization Server with Okta Python SDK Source: https://github.com/okta/okta-sdk-python/blob/master/docs/AuthorizationServerApi.md This code example shows how to delete an authorization server using the Okta Python SDK. It requires an authenticated ApiClient and the ID of the authorization server to be deleted. The example includes setup for API key or OAuth authentication and basic error handling. ```python import okta from okta.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://subdomain.okta.com # See configuration.py for a list of all supported configuration parameters. configuration = okta.Configuration( host = "https://subdomain.okta.com" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure API key authorization: apiToken configuration.api_key['apiToken'] = os.environ["API_KEY"] # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed # configuration.api_key_prefix['apiToken'] = 'Bearer' configuration.access_token = os.environ["ACCESS_TOKEN"] # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.AuthorizationServerApi(api_client) auth_server_id = 'GeGRTEr7f3yu2n7grw22' # str | `id` of the Authorization Server try: # Delete an Authorization Server api_instance.delete_authorization_server(auth_server_id) except Exception as e: print("Exception when calling AuthorizationServerApi->delete_authorization_server: %s\n" % e) ``` -------------------------------- ### Create User with Okta Python SDK Source: https://github.com/okta/okta-sdk-python/blob/master/docs/UserApi.md Demonstrates how to create a new user in Okta using the Python SDK. It shows configuration for API key or OAuth authentication and how to instantiate the UserApi client. The example includes setting up the request body and optional parameters like activation and next login behavior. It handles potential API exceptions. ```python import okta from okta.models.create_user_request import CreateUserRequest from okta.models.user import User from okta.models.user_next_login import UserNextLogin from okta.rest import ApiException from pprint import pprint import os # Defining the host is optional and defaults to https://subdomain.okta.com # See configuration.py for a list of all supported configuration parameters. configuration = okta.Configuration( host = "https://subdomain.okta.com" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure API key authorization: apiToken configuration.api_key['apiToken'] = os.environ["API_KEY"] # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed # configuration.api_key_prefix['apiToken'] = 'Bearer' configuration.access_token = os.environ["ACCESS_TOKEN"] # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.UserApi(api_client) body = okta.CreateUserRequest() # CreateUserRequest | activate = True # bool | Executes activation lifecycle operation when creating the user (optional) (default to True) provider = False # bool | Indicates whether to create a user with a specified authentication provider (optional) (default to False) next_login = okta.UserNextLogin() # UserNextLogin | With activate=true, set nextLogin to "changePassword" to have the password be EXPIRED, so user must change it the next time they log in. (optional) try: # Create a User api_response = api_instance.create_user(body, activate=activate, provider=provider, next_login=next_login) print("The response of UserApi->create_user:\n") pprint(api_response) except Exception as e: print("Exception when calling UserApi->create_user: %s\n" % e) ``` -------------------------------- ### ProfileEnrollmentPolicyRule Python Example Source: https://github.com/okta/okta-sdk-python/blob/master/docs/ProfileEnrollmentPolicyRule.md Demonstrates how to create a ProfileEnrollmentPolicyRule instance from a JSON string and a dictionary in Python. It also shows how to convert the instance back to a JSON string and a dictionary. This requires the 'okta' library to be installed. ```python from okta.models.profile_enrollment_policy_rule import ProfileEnrollmentPolicyRule # TODO update the JSON string below json_string = "{}" # create an instance of ProfileEnrollmentPolicyRule from a JSON string profile_enrollment_policy_rule_instance = ProfileEnrollmentPolicyRule.from_json(json_string) # print the JSON string representation of the object print(ProfileEnrollmentPolicyRule.to_json()) # convert the object into a dict profile_enrollment_policy_rule_dict = profile_enrollment_policy_rule_instance.to_dict() # create an instance of ProfileEnrollmentPolicyRule from a dict profile_enrollment_policy_rule_from_dict = ProfileEnrollmentPolicyRule.from_dict(profile_enrollment_policy_rule_dict) ``` -------------------------------- ### Configure Okta API Client and Retrieve Preview Sign-in Page (Python) Source: https://github.com/okta/okta-sdk-python/blob/master/docs/CustomizationApi.md Demonstrates how to configure the Okta API client using API key or access token authentication and then retrieve a preview of the sign-in page for a given brand ID. It includes error handling for potential exceptions during the API call. Dependencies include the 'okta' package and the 'os' module for environment variables. ```python import okta from okta.rest import ApiException from pprint import pprint import os # Defining the host is optional and defaults to https://subdomain.okta.com # See configuration.py for a list of all supported configuration parameters. configuration = okta.Configuration( host = "https://subdomain.okta.com" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure API key authorization: apiToken configuration.api_key['apiToken'] = os.environ["API_KEY"] # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed # configuration.api_key_prefix['apiToken'] = 'Bearer' configuration.access_token = os.environ["ACCESS_TOKEN"] # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.CustomizationApi(api_client) brand_id = 'brand_id_example' # str | The ID of the brand try: # Retrieve the Preview Sign-in Page Preview api_response = api_instance.get_preview_sign_in_page(brand_id) print("The response of CustomizationApi->get_preview_sign_in_page:\n") pprint(api_response) except Exception as e: print("Exception when calling CustomizationApi->get_preview_sign_in_page: %s\n" % e) ``` -------------------------------- ### Implement Custom Cache Driver Source: https://github.com/okta/okta-sdk-python/blob/master/README.md Provides a fully working example of a custom cache driver by inheriting from `okta.cache.cache.Cache`. This implementation uses a dictionary to store cache entries and supports add, get, contains, and delete operations. ```python # Fully working example for Custom Cache class from okta.cache.cache import Cache class CacheImpl(Cache): def __init__(self): super().__init__() self.cache_dict = {} def add(self, key, value): self.cache_dict[key] = value def get(self, key): return self.cache_dict.get(key, None) def contains(self, key): return key in self.cache_dict def delete(self, key): if self.contains(key): del self.cache_dict[key] ``` -------------------------------- ### Okta Client Initialization with Configuration Source: https://github.com/okta/okta-sdk-python/blob/master/README.md Demonstrates initializing the Okta Python client. It shows how to configure the client using a dictionary containing the Okta domain and API token. For production environments, it's recommended to use more secure methods for storing credentials. ```python from okta.client import Client as OktaClient # Configuration dictionary for the Okta client config = { 'orgUrl': 'https://your.okta.com', # Replace with your Okta domain 'token': 'your_api_token' # Replace with your API token } # Initialize the Okta client okta_client = OktaClient(config) ``` -------------------------------- ### Okta SDK Python: Retrieve a User Source: https://github.com/okta/okta-sdk-python/blob/master/docs/UserApi.md This code demonstrates how to retrieve a user's information from Okta using their user ID. It utilizes the Okta Python SDK and expects a User object in return. The example shows setup for both API key and OAuth authentication. ```python import okta import os from okta.models.user import User from okta.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://subdomain.okta.com configuration = okta.Configuration( host = "https://subdomain.okta.com" ) # Configure API key authorization: apiToken configuration.api_key['apiToken'] = os.environ["API_KEY"] # Configure OAuth2 authentication configuration.access_token = os.environ["ACCESS_TOKEN"] # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.UserApi(api_client) user_id = 'user_id_example' # str | try: # Retrieve a User api_response = api_instance.get_user(user_id) print("The response of UserApi->get_user:\n") pprint(api_response) except Exception as e: print("Exception when calling UserApi->get_user: %s\n" % e) ``` -------------------------------- ### Basic User Management with Okta Python SDK Source: https://github.com/okta/okta-sdk-python/blob/master/README.md Demonstrates creating a user with profile information and credentials, then listing all users and printing their names. This example requires Python 3.7.0+, the 'okta' package, and valid Okta configuration (orgUrl and token). It uses asyncio for asynchronous operations. ```python import asyncio from okta import UserProfile, PasswordCredential, CreateUserRequest, UserNextLogin, UserCredentials from okta.client import Client as OktaClient config = { 'orgUrl': 'https://{your_org}.okta.com', 'token': 'YOUR_API_TOKEN', } okta_client = OktaClient(config) user_config = { "firstName": "Sample", "lastName": "Sample", "email": "sample12.sample@example.com", "login": "sample12.sample@example.com", "mobilePhone": "555-415-1337" } user_profile = UserProfile(**user_config) password_value = { "value": "Knock*knock*neo*111" } password_credential = PasswordCredential(**password_value) user_credentials = { "password": password_credential } user_credentials = UserCredentials(**user_credentials) create_user_request = { "profile": user_profile, "credentials": user_credentials, } user_request = CreateUserRequest(**create_user_request) async def users(): next_login = UserNextLogin(UserNextLogin.CHANGEPASSWORD) user, resp, err = await okta_client.create_user(user_request, activate=True, provider=False, next_login=next_login) print("The response of UserApi->create_user:\n") print(user) print(resp, err) users, resp, err = await okta_client.list_users() for user in users: print(user.profile.first_name, user.profile.last_name) try: print(user.profile.customAttr) except: print('User has no customAttr') loop = asyncio.get_event_loop() loop.run_until_complete(users()) ``` -------------------------------- ### Convert ResourceSetBindingMember to JSON and Dictionary in Python Source: https://github.com/okta/okta-sdk-python/blob/master/docs/ResourceSetBindingMember.md This example shows how to convert a ResourceSetBindingMember object into its dictionary representation using `to_dict()` and then create a new instance from this dictionary using `from_dict()`. It also demonstrates how to get the JSON string representation of the object using `to_json()`. ```python from okta.models.resource_set_binding_member import ResourceSetBindingMember # Assuming resource_set_binding_member_instance is an existing ResourceSetBindingMember object # For demonstration, let's create a placeholder instance json_data = "{}" resource_set_binding_member_instance = ResourceSetBindingMember.from_json(json_data) # print the JSON string representation of the object print(ResourceSetBindingMember.to_json()) # convert the object into a dict resource_set_binding_member_dict = resource_set_binding_member_instance.to_dict() # create an instance of ResourceSetBindingMember from a dict resource_set_binding_member_from_dict = ResourceSetBindingMember.from_dict(resource_set_binding_member_dict) ``` -------------------------------- ### Provisioning Configurations Source: https://github.com/okta/okta-sdk-python/blob/master/README.md Documentation for provisioning configurations, including connections, actions, and conditions. ```APIDOC ## Provisioning Configurations ### Description Manages the configuration of provisioning processes, including connections, actions for various states (suspended, deprovisioned), and conditions. ### Endpoints - `Provisioning`: Base object for provisioning settings. - `ProvisioningAction`: An action to be performed during provisioning. - `ProvisioningConditions`: Conditions that trigger provisioning actions. - `ProvisioningConnection`: Configuration for a provisioning connection. - `ProvisioningConnectionAuthScheme`: Authentication scheme for a provisioning connection. - `ProvisioningConnectionProfile`: Profile details for a provisioning connection. - `ProvisioningConnectionProfileOauth`: OAuth specific profile details. - `ProvisioningConnectionProfileToken`: Token details for a provisioning connection. - `ProvisioningConnectionProfileUnknown`: Represents an unknown profile type. - `ProvisioningConnectionRequest`: Request object for provisioning connections. - `ProvisioningConnectionStatus`: Status of a provisioning connection. - `ProvisioningDeprovisionedAction`: Action for deprovisioned state. - `ProvisioningDeprovisionedCondition`: Condition for deprovisioned state. - `ProvisioningGroups`: Settings related to provisioning groups. - `ProvisioningGroupsAction`: Action for provisioning groups. - `ProvisioningSuspendedAction`: Action for suspended state. - `ProvisioningSuspendedCondition`: Condition for suspended state. ### Parameters No direct parameters are documented here as these are primarily object definitions. ``` -------------------------------- ### BookmarkApplicationSettingsApplication Model Initialization and Conversion (Python) Source: https://github.com/okta/okta-sdk-python/blob/master/docs/BookmarkApplicationSettingsApplication.md Demonstrates how to create a BookmarkApplicationSettingsApplication instance from a JSON string and a dictionary. It also shows how to convert the instance back to JSON and a dictionary. This model is part of the Okta SDK for Python. ```python from okta.models.bookmark_application_settings_application import BookmarkApplicationSettingsApplication # TODO update the JSON string below json_string = "{}" # create an instance of BookmarkApplicationSettingsApplication from a JSON string bookmark_application_settings_application_instance = BookmarkApplicationSettingsApplication.from_json(json_string) # print the JSON string representation of the object print(BookmarkApplicationSettingsApplication.to_json()) # convert the object into a dict bookmark_application_settings_application_dict = bookmark_application_settings_application_instance.to_dict() # create an instance of BookmarkApplicationSettingsApplication from a dict bookmark_application_settings_application_from_dict = BookmarkApplicationSettingsApplication.from_dict(bookmark_application_settings_application_dict) ``` -------------------------------- ### Retrieve Certificate Signing Request (Python) Source: https://github.com/okta/okta-sdk-python/blob/master/docs/IdentityProviderApi.md Retrieves a specific Certificate Signing Request (CSR) model by its ID. This operation requires an API client instance, the IdP ID, and the CSR ID. It returns a Csr object. The example is a starting point and assumes the necessary imports and client configuration are in place. ```python import okta from okta.models.csr import Csr from okta.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://subdomain.okta.com ``` -------------------------------- ### Basic Asynchronous Okta Client Usage with asyncio Source: https://github.com/okta/okta-sdk-python/blob/master/README.md Illustrates the fundamental usage of the Okta client in an asynchronous context using Python's `asyncio` library. It shows how to initialize the client, call asynchronous methods like `list_users`, and run the main asynchronous function using `asyncio.get_event_loop()`. ```python from okta.client import Client as OktaClient import asyncio async def main(): client = OktaClient() users, resp, err = await client.list_users() print(len(users)) loop = asyncio.get_event_loop() loop.run_until_complete(main()) ``` -------------------------------- ### Create Okta Brand using Python Source: https://github.com/okta/okta-sdk-python/blob/master/docs/CustomizationApi.md This snippet demonstrates how to create a new brand within your Okta organization using the Python SDK. It shows the instantiation of the API client and the `CustomizationApi`, along with parameters for pagination and searching. Error handling is included. ```python import okta from pprint import pprint # Assuming 'configuration' is already set up # configuration = okta.Configuration(...) # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.CustomizationApi(api_client) expand = ['expand_example'] # List[str] | Specifies additional metadata to be included in the response (optional) after = 'after_example' # str | The cursor to use for pagination. It is an opaque string that specifies your current location in the list and is obtained from the `Link` response header. See [Pagination](/#pagination) for more information. (optional) limit = 20 # int | A limit on the number of objects to return (optional) (default to 20) q = 'q_example' # str | Searches the records for matching value (optional) create_brand_request = okta.CreateBrandRequest() # CreateBrandRequest | (optional) try: # Create a Brand api_response = api_instance.create_brand(expand=expand, after=after, limit=limit, q=q, create_brand_request=create_brand_request) print("The response of CustomizationApi->create_brand:\n") pprint(api_response) except Exception as e: print("Exception when calling CustomizationApi->create_brand: %s\n" % e) ``` -------------------------------- ### Revoke Okta Support Access (Python) Source: https://github.com/okta/okta-sdk-python/blob/master/docs/OrgSettingApi.md This Python function, using the Okta SDK, revokes Okta Support's access to your organization. It requires authentication setup (API key or OAuth2) and returns an OrgOktaSupportSettingsObj upon successful revocation. The example includes basic configuration and error handling for the API call. ```python import okta from okta.models.org_okta_support_settings_obj import OrgOktaSupportSettingsObj from okta.rest import ApiException from pprint import pprint configuration = okta.Configuration( host = "https://subdomain.okta.com" ) # The client must configure the authentication and authorization parameters # Example for API key authentication: # configuration.api_key['apiToken'] = os.environ["API_KEY"] # Example for OAuth2 authentication: # configuration.access_token = os.environ["ACCESS_TOKEN"] # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.OrgSettingApi(api_client) try: # Revoke Okta Support access api_response = api_instance.revoke_okta_support() print("The response of OrgSettingApi->revoke_okta_support:\n") pprint(api_response) except Exception as e: print("Exception when calling OrgSettingApi->revoke_okta_support: %s\n" % e) ``` -------------------------------- ### Activate Authorization Server Policy with Okta SDK for Python Source: https://github.com/okta/okta-sdk-python/blob/master/docs/AuthorizationServerApi.md This code example demonstrates activating a specific policy for an authorization server using the Okta SDK for Python. It requires the authorization server ID and the policy ID. The function call includes error handling for potential API exceptions. ```python import okta from okta.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://subdomain.okta.com # See configuration.py for a list of all supported configuration parameters. configuration = okta.Configuration( host = "https://subdomain.okta.com" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure API key authorization: apiToken configuration.api_key['apiToken'] = os.environ["API_KEY"] # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed # configuration.api_key_prefix['apiToken'] = 'Bearer' configuration.access_token = os.environ["ACCESS_TOKEN"] # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.AuthorizationServerApi(api_client) auth_server_id = 'GeGRTEr7f3yu2n7grw22' # str | `id` of the Authorization Server policy_id = '00plrilJ7jZ66Gn0X0g3' # str | `id` of the Policy try: # Activate a Policy api_instance.activate_authorization_server_policy(auth_server_id, policy_id) except Exception as e: print("Exception when calling AuthorizationServerApi->activate_authorization_server_policy: %s\n" % e) ``` -------------------------------- ### List all Okta Event Hooks using Python SDK Source: https://github.com/okta/okta-sdk-python/blob/master/docs/EventHookApi.md Lists all Event Hooks configured within the Okta organization. This operation requires an authenticated Okta API client and returns a list of EventHook objects. The example shows basic setup for authentication and making the API call. ```python import okta from okta.models.event_hook import EventHook from okta.rest import ApiException from pprint import pprint import os # Assuming 'configuration' is already set up with API credentials # and 'okta.ApiClient(configuration)' creates 'api_client' configuration = okta.Configuration( host = "https://subdomain.okta.com" ) configuration.api_key['apiToken'] = os.environ["API_KEY"] configuration.access_token = os.environ["ACCESS_TOKEN"] with okta.ApiClient(configuration) as api_client: api_instance = okta.EventHookApi(api_client) try: # List all Event Hooks api_response = api_instance.list_event_hooks() print("The response of EventHookApi->list_event_hooks:\n") pprint(api_response) except Exception as e: print("Exception when calling EventHookApi->list_event_hooks: %s\n" % e) ``` -------------------------------- ### Instantiate SecurePasswordStoreApplicationSettings from JSON - Python Source: https://github.com/okta/okta-sdk-python/blob/master/docs/SecurePasswordStoreApplicationSettings.md Demonstrates how to create an instance of SecurePasswordStoreApplicationSettings by parsing a JSON string. This is useful for initializing objects from external data sources. Requires the `okta.models.secure_password_store_application_settings` module. ```python from okta.models.secure_password_store_application_settings import SecurePasswordStoreApplicationSettings # TODO update the JSON string below json_string = "{}" # create an instance of SecurePasswordStoreApplicationSettings from a JSON string sa_instance = SecurePasswordStoreApplicationSettings.from_json(json_string) ``` -------------------------------- ### Delete Role in Okta Python SDK Source: https://github.com/okta/okta-sdk-python/blob/master/docs/RoleApi.md This code snippet illustrates how to delete a role from Okta using the Python SDK. It requires the role's ID or label as a parameter. The example shows the setup of the API client with authentication details and the subsequent call to the delete_role method from the RoleApi. Exception handling is provided. ```python import okta from okta.rest import ApiException from pprint import pprint import os configuration = okta.Configuration( host = "https://subdomain.okta.com" ) configuration.api_key['apiToken'] = os.environ["API_KEY"] configuration.access_token = os.environ["ACCESS_TOKEN"] with okta.ApiClient(configuration) as api_client: api_instance = okta.RoleApi(api_client) role_id_or_label = 'cr0Yq6IJxGIr0ouum0g3' try: api_instance.delete_role(role_id_or_label) except Exception as e: print("Exception when calling RoleApi->delete_role: %s\n" % e) ``` -------------------------------- ### Instantiate SwaApplicationSettingsApplication from JSON/Dict - Python Source: https://github.com/okta/okta-sdk-python/blob/master/docs/SwaApplicationSettingsApplication.md Demonstrates how to create an instance of SwaApplicationSettingsApplication using either a JSON string or a Python dictionary. It also shows how to convert the object back to JSON or a dictionary. This is useful for integrating with Okta's API or for data persistence. ```python from okta.models.swa_application_settings_application import SwaApplicationSettingsApplication # TODO update the JSON string below json_data = "{}" # create an instance of SwaApplicationSettingsApplication from a JSON string swa_application_settings_application_instance = SwaApplicationSettingsApplication.from_json(json_data) # print the JSON string representation of the object print(SwaApplicationSettingsApplication.to_json()) # convert the object into a dict swa_application_settings_application_dict = swa_application_settings_application_instance.to_dict() # create an instance of SwaApplicationSettingsApplication from a dict swa_application_settings_application_from_dict = SwaApplicationSettingsApplication.from_dict(swa_application_settings_application_dict) ``` -------------------------------- ### Retrieve Agent Pool Update Instance using Okta SDK Python Source: https://github.com/okta/okta-sdk-python/blob/master/docs/AgentPoolsApi.md Retrieves details of a specific agent pool update using its pool ID and update ID. The function returns an AgentPoolUpdate object containing the update's information. The example shows client configuration and the API call, with placeholders for authentication setup. ```python import okta from okta.models.agent_pool_update import AgentPoolUpdate from okta.rest import ApiException from pprint import pprint # Configuration and API client setup configuration = okta.Configuration(host="https://subdomain.okta.com") # Assuming configuration is already set up with API key or OAuth token # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.AgentPoolsApi(api_client) pool_id = 'pool_id_example' # str | Id of the agent pool update_id = 'update_id_example' # str | Id of the update try: # Retrieve an Agent Pool update instance api_response: AgentPoolUpdate = api_instance.get_agent_pools_update_instance(pool_id, update_id) print("Agent pool update details:\n") pprint(api_response) except Exception as e: print("Exception when calling AgentPoolsApi->get_agent_pools_update_instance: %s\n" % e) ``` -------------------------------- ### Install Okta Python SDK using Setuptools Source: https://github.com/okta/okta-sdk-python/blob/master/README.md Installs the Okta Python SDK directly from a cloned repository using Setuptools. This method is useful for development or when installing from a local copy. It requires Python and Setuptools to be installed. ```sh python setup.py install --user ``` -------------------------------- ### Configure Okta API Client and List OAuth2 Clients (Python) Source: https://github.com/okta/okta-sdk-python/blob/master/docs/AuthorizationServerApi.md This snippet demonstrates how to set up the Okta Python SDK client using API key or OAuth2 authentication and then lists all OAuth2 clients associated with a given authorization server. It includes error handling for the API request. ```python import okta from okta.models.o_auth2_client import OAuth2Client from okta.rest import ApiException from pprint import pprint import os # Defining the host is optional and defaults to https://subdomain.okta.com # See configuration.py for a list of all supported configuration parameters. configuration = okta.Configuration( host = "https://subdomain.okta.com" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure API key authorization: apiToken configuration.api_key['apiToken'] = os.environ["API_KEY"] # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed # configuration.api_key_prefix['apiToken'] = 'Bearer' configuration.access_token = os.environ["ACCESS_TOKEN"] # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.AuthorizationServerApi(api_client) auth_server_id = 'GeGRTEr7f3yu2n7grw22' # str | `id` of the Authorization Server try: # List all Clients api_response = api_instance.list_o_auth2_clients_for_authorization_server(auth_server_id) print("The response of AuthorizationServerApi->list_o_auth2_clients_for_authorization_server:\n") pprint(api_response) except Exception as e: print("Exception when calling AuthorizationServerApi->list_o_auth2_clients_for_authorization_server: %s\n" % e) ``` -------------------------------- ### GET /api/v1/ui/schemas Source: https://github.com/okta/okta-sdk-python/blob/master/docs/UISchemaApi.md Lists all UI Schemas available in your Okta organization. This is useful for getting an overview of all available schemas. ```APIDOC ## GET /api/v1/ui/schemas ### Description Lists all UI Schemas in your org. ### Method GET ### Endpoint /api/v1/ui/schemas #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **List[UISchemasResponseObject]** - A list of UI Schema objects. #### Response Example ```json [ { "id": "uis4a7liocgcRgcxZ0g7", "name": "uischema.default", "schema": { ... } }, { "id": "uis4b8ljodhcRgyu10h8", "name": "uischema.custom", "schema": { ... } } ] ``` #### Error Responses - **403** - Forbidden - **404** - Not Found - **429** - Too Many Requests ``` -------------------------------- ### Create User with Okta SDK for Python (Before) Source: https://github.com/okta/okta-sdk-python/blob/master/UPGRADE_GUIDE.md This Python code snippet demonstrates an older method of creating a user with the Okta SDK. It directly passes a dictionary for user creation and includes a loop to list users and print their names, with error handling for custom attributes. Dependencies include the 'okta' package. ```python from okta.client import Client as OktaClient config = { 'orgUrl': 'https://{your_org}.okta.com', 'token': 'YOUR_API_TOKEN', } async def main(): client = OktaClient() # create user with custom attribute body = { "profile": { "firstName": "John", "lastName": "Smith", "email": "jsmith@matrix.com", "login": "jsmith@matrix.com", "customAttr": "custom value" }, "credentials": { "password": { "value": "Knock knock*neo*111" } } } result = await client.create_user(body) #create user without custom attribute body = { "profile": { "firstName": "Neo", "lastName": "Anderson", "email": "nanderson@matrix.com", "login": "nanderson@matrix.com" }, "credentials": { "password": { "value": "Knock*knock*neo*111" } } } result = await client.create_user(body) users, resp, err await client.list_users() for user in users: print(user.profile.first_name, user.profile.last_name) try: print(user.profile.customAttr) except: print('User has no customAttr') loop = asyncio.get_event_loop() loop.run_until_complete(main()) ``` -------------------------------- ### Configure Okta Client with Caching and Logging in Python Source: https://context7.com/okta/okta-sdk-python/llms.txt Demonstrates setting up the OktaClient with advanced configurations including enabling caching with specific time-to-idle and time-to-live settings, and enabling logging with a specified log level. It also shows how to set and retrieve custom request headers. ```python from okta.client import Client as OktaClient import asyncio config = { 'orgUrl': 'https://dev-12345.okta.com', 'token': 'YOUR_API_TOKEN', 'cache': { 'enabled': True, 'defaultTti': 300, # Time to idle in seconds 'defaultTtl': 600 # Time to live in seconds }, 'logging': { 'enabled': True, 'logLevel': 'DEBUG' # DEBUG, INFO, WARNING, ERROR }, 'rateLimit': { 'maxRetries': 4 }, 'requestTimeout': 30, # seconds 'connectionTimeout': 30 # seconds } client = OktaClient(config) async def use_custom_headers(): # Set custom headers for all requests custom_headers = { 'X-Custom-Header': 'custom-value', 'X-Request-ID': 'req-12345' } client.set_custom_headers(custom_headers) # Make requests with custom headers users, resp, err = await client.list_users({'limit': '5'}) # Get current custom headers current_headers = client.get_custom_headers() print(f"Custom headers: {current_headers}") # Get default headers default_headers = client.get_default_headers() print(f"Default headers: {default_headers}") # Clear custom headers client.clear_custom_headers() print("Custom headers cleared") loop = asyncio.get_event_loop() loop.run_until_complete(use_custom_headers()) ``` -------------------------------- ### Get Org Settings - Python Source: https://github.com/okta/okta-sdk-python/blob/master/docs/OrgSettingApi.md Retrieves the overall organization settings. This GET request does not require any input parameters. ```python import okta from okta.rest import ApiException from pprint import pprint # ... (configuration and authentication setup as in the previous example) try: api_client = okta.ApiClient(configuration) org_setting_api = okta.OrgSettingApi(api_client) # Call the API method to get org settings response = org_setting_api.get_org_settings() pprint(response) except ApiException as e: print(f"Exception when calling OrgSettingApi->get_org_settings: {e}") ``` -------------------------------- ### Configure Okta API Client and Retrieve Sign-in Page Sub-Resources (Python) Source: https://github.com/okta/okta-sdk-python/blob/master/docs/CustomizationApi.md This Python code demonstrates configuring the Okta API client with API key or OAuth2 authentication and then retrieving sign-in page sub-resources. It shows how to optionally expand specific sub-resources using the 'expand' parameter and includes basic error handling. The code requires the 'okta' library and 'os' for environment variables. ```python import okta from okta.models.page_root import PageRoot from okta.rest import ApiException from pprint import pprint import os # Defining the host is optional and defaults to https://subdomain.okta.com # See configuration.py for a list of all supported configuration parameters. configuration = okta.Configuration( host = "https://subdomain.okta.com" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure API key authorization: apiToken configuration.api_key['apiToken'] = os.environ["API_KEY"] # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed # configuration.api_key_prefix['apiToken'] = 'Bearer' configuration.access_token = os.environ["ACCESS_TOKEN"] # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.CustomizationApi(api_client) brand_id = 'brand_id_example' # str | The ID of the brand expand = ['expand_example'] # List[str] | Specifies additional metadata to be included in the response (optional) try: # Retrieve the Sign-in Page Sub-Resources api_response = api_instance.get_sign_in_page(brand_id, expand=expand) print("The response of CustomizationApi->get_sign_in_page:\n") pprint(api_response) except Exception as e: print("Exception when calling CustomizationApi->get_sign_in_page: %s\n" % e) ``` -------------------------------- ### Get Org Preferences - Python Source: https://github.com/okta/okta-sdk-python/blob/master/docs/OrgSettingApi.md Retrieves the general organization preferences. This GET request does not require any input parameters. ```python import okta from okta.rest import ApiException from pprint import pprint # ... (configuration and authentication setup as in the previous example) try: api_client = okta.ApiClient(configuration) org_setting_api = okta.OrgSettingApi(api_client) # Call the API method to get org preferences response = org_setting_api.get_org_preferences() pprint(response) except ApiException as e: print(f"Exception when calling OrgSettingApi->get_org_preferences: {e}") ``` -------------------------------- ### Get Okta Support Settings - Python Source: https://github.com/okta/okta-sdk-python/blob/master/docs/OrgSettingApi.md Retrieves the Okta support settings for the organization. This GET request does not require any input parameters. ```python import okta from okta.rest import ApiException from pprint import pprint # ... (configuration and authentication setup as in the previous example) try: api_client = okta.ApiClient(configuration) org_setting_api = okta.OrgSettingApi(api_client) # Call the API method to get Okta support settings response = org_setting_api.get_org_okta_support_settings() pprint(response) except ApiException as e: print(f"Exception when calling OrgSettingApi->get_org_okta_support_settings: {e}") ``` -------------------------------- ### Instantiate and Convert OpenIdConnectApplicationSettingsClient (Python) Source: https://github.com/okta/okta-sdk-python/blob/master/docs/OpenIdConnectApplicationSettingsClient.md Demonstrates how to create an instance of OpenIdConnectApplicationSettingsClient from a JSON string and convert it to a dictionary. It also shows how to convert the object back to its JSON string representation. This requires the 'okta' library to be installed. ```python from okta.models.open_id_connect_application_settings_client import OpenIdConnectApplicationSettingsClient # TODO update the JSON string below json_string = "{}" # create an instance of OpenIdConnectApplicationSettingsClient from a JSON string open_id_connect_application_settings_client_instance = OpenIdConnectApplicationSettingsClient.from_json(json_string) # print the JSON string representation of the object print(OpenIdConnectApplicationSettingsClient.to_json()) # convert the object into a dict open_id_connect_application_settings_client_dict = open_id_connect_application_settings_client_instance.to_dict() # create an instance of OpenIdConnectApplicationSettingsClient from a dict open_id_connect_application_settings_client_from_dict = OpenIdConnectApplicationSettingsClient.from_dict(open_id_connect_application_settings_client_dict) ``` -------------------------------- ### GET /api/v1/hookKeys/{hookKeyId} Source: https://github.com/okta/okta-sdk-python/blob/master/docs/HookKeyApi.md Retrieves a specific hook key by its ID. This endpoint is used to get details about an existing hook key. ```APIDOC ## GET /api/v1/hookKeys/{hookKeyId} ### Description Retrieves a specific hook key by its ID. This endpoint is used to get details about an existing hook key. ### Method GET ### Endpoint /api/v1/hookKeys/{hookKeyId} ### Parameters #### Path Parameters - **hook_key_id** (str) - Required - `id` of the Hook Key ### Request Example ```python # Example using the okta-sdk-python import okta from pprint import pprint # Assuming 'configuration' is already set up # with okta.ApiClient(configuration) as api_client: # api_instance = okta.HookKeyApi(api_client) # hook_key_id = 'XreKU5laGwBkjOTehusG' # str | `id` of the Hook Key # api_response = api_instance.get_hook_key(hook_key_id) # pprint(api_response) ``` ### Response #### Success Response (200) - **HookKey** (HookKey) - Details of the hook key. #### Response Example ```json { "id": "XreKU5laGwBkjOTehusG", "created": "2023-01-01T12:00:00.000Z", "lastUpdated": "2023-01-01T12:00:00.000Z", "kid": "some_kid_value" } ``` #### Error Responses - **403** Forbidden - **404** Not Found - **429** Too Many Requests ``` -------------------------------- ### Upload Brand Theme Background Image with Okta SDK in Python Source: https://github.com/okta/okta-sdk-python/blob/master/docs/CustomizationApi.md This code example demonstrates how to upload a background image for a brand theme using the Okta SDK for Python. It initializes the API client with the configured authentication, creates an instance of the CustomizationApi, and calls the upload_brand_theme_background_image method with the appropriate brand and theme IDs. Error handling is included for potential exceptions during the API call. ```python import okta from okta.rest import ApiException from pprint import pprint # Defining the host is optional and defaults to https://subdomain.okta.com # See configuration.py for a list of all supported configuration parameters. configuration = okta.Configuration( host = "https://subdomain.okta.com" ) # The client must configure the authentication and authorization parameters # in accordance with the API server security policy. # Examples for each auth method are provided below, use the example that # satisfies your auth use case. # Configure API key authorization: apiToken configuration.api_key['apiToken'] = os.environ["API_KEY"] # Uncomment below to setup prefix (e.g. Bearer) for API key, if needed # configuration.api_key_prefix['apiToken'] = 'Bearer' configuration.access_token = os.environ["ACCESS_TOKEN"] # Enter a context with an instance of the API client with okta.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = okta.CustomizationApi(api_client) brand_id = 'brand_id_example' # str | The ID of the brand theme_id = 'theme_id_example' # str | The ID of the theme file = None # bytearray | try: # Upload the Background Image api_response = api_instance.upload_brand_theme_background_image(brand_id, theme_id, file) print("The response of CustomizationApi->upload_brand_theme_background_image:\n") pprint(api_response) except Exception as e: print("Exception when calling CustomizationApi->upload_brand_theme_background_image: %s\n" % e) ```