A Python package for calling Okta APIs using the requests module.
This package has the following scripts defined by the pyproject.toml file:
okta-server-enrollment-token: Generates a server enrollment token for a specified project within an Okta team. This token can be used to enroll servers into Okta for identity and access management.
okta/
├── src
│ └── main/python
│ | └── okta_api_script/
│ | ├── __init__.py
│ | ├── main.py # Main API logic
│ | └── cli.py # Command line interface
│ └── test/python
│ ├── test/python
│ ├── __init__.py
│ └── test_main.py # Unit tests
├── pyproject.toml # Project configuration
├── justfile # Build automation
└── README.md # This file
-
This project is meant to be developed using
direnvfor environment variable management. Ensure you havedirenvinstalled and configured in your shell, or that you are using the provided devcontainer setup. You can also skip this step if you set those values previously or are using some other method to manage environment variables. -
Initialize the project:
cp DOTENV .envrc # Modifiy .envrc with your environment variables direnv allowjust init
-
Install development dependencies:
just dev-install
-
Set your environment variables:
export KEY_ID="your-key-id" export KEY_SECRET="your-key-secret"
-
Run the script:
just run # Run as Python module just run-cli # Run via CLI entry point
The main script (okta_api_script.main) orchestrates the Okta API workflow:
- Authenticates with Okta using service credentials to obtain a bearer token
- Retrieves resource groups for your team
- Fetches projects for each resource group
- Generates a server enrollment token for your target project
just runfrom okta_api_script.main import execute_api_cycle
execute_api_cycle(
org_name="your-org",
team_name="your-team",
target_project="your-project",
key_id="your-key-id",
key_secret="your-key-secret",
output_json=False
)The execute_api_cycle() function accepts the following parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
org_name |
str | None |
No | Okta organization name. If not provided, reads from OKTA_ORG environment variable |
team_name |
str | None |
No | Team name. If not provided, reads from OKTA_TEAM environment variable |
target_project |
str | None |
No | Target project name. If not provided, reads from OKTA_TARGET_PROJECT environment variable |
key_id |
str | None |
No | Okta API key ID. If not provided, reads from KEY_ID environment variable |
key_secret |
str | None |
No | Okta API key secret. If not provided, reads from KEY_SECRET environment variable |
output_json |
bool |
No | If True, outputs full response as formatted JSON. If False (default), outputs only the enrollment token |
The following environment variables are used by the script:
OKTA_ORG: Your Okta organization name (e.g.,noaa)OKTA_TEAM: Your team name (e.g.,nos-coastal-modeling-cloud-sandbox)OKTA_TARGET_PROJECT: Your target project nameKEY_ID: Your Okta API key IDKEY_SECRET: Your Okta API key secret
All environment variables must be set for the script to run successfully. You can set them in:
- Your shell environment
.envrcfile (withdirenv)- Command line arguments to the
execute_api_cycle()function
just --list