okta provider for stackql
This repository is used to generate and document the Okta provider for StackQL, allowing you to query and manipulate Okta resources using SQL-like syntax. The provider is built using the @stackql/provider-utils package, which provides tools for converting OpenAPI specifications into StackQL-compatible provider schemas.
The @stackql/provider-utils package offers several utilities that this provider uses:
split- Divides a large OpenAPI spec into smaller service-specific filesanalyze- Examines OpenAPI specs and generates mapping configuration filesgenerate- Creates StackQL provider extensions from OpenAPI specs and mappingsdocgen- Builds documentation for the provider
To use the Okta provider with StackQL, you'll need:
- An Okta account with appropriate API credentials
- An Okta API token with sufficient permissions for the resources you want to access, export this as
OKTA_API_TOKEN - StackQL CLI installed on your system (see StackQL)
First, download the Okta Management API OpenAPI specification:
curl -L https://raw.githubusercontent.com/okta/okta-management-openapi-spec/master/dist/current/management-minimal.yaml \
-o provider-dev/downloaded/management-minimal.yamlThis downloads the official Okta Management API specification, which defines all available API endpoints, request parameters, and response schemas.
Next, split the monolithic OpenAPI specification into service-specific files:
npm run split -- \
--provider-name okta \
--api-doc provider-dev/downloaded/management-minimal.yaml \
--svc-discriminator path \
--output-dir provider-dev/source \
--overwriteThis step breaks down the large Okta API specification into smaller, more manageable service files. The --svc-discriminator path option tells the tool to use the URL path structure to determine which API endpoints belong to which service. For Okta, this creates separate files for different functional areas like users, groups, applications, etc.
Generate the mapping configuration that connects OpenAPI operations to StackQL resources:
npm run generate-mappings -- \
--provider-name okta \
--input-dir provider-dev/source \
--output-dir provider-dev/configThis step analyzes the service specs and creates a CSV mapping file that defines how OpenAPI operations translate to StackQL resources, methods, and SQL verbs. The mapping process handles two scenarios:
-
New Provider Development: If no mapping file exists yet, this creates a new
all_services.csvfile with all operations from the OpenAPI spec. You'll need to edit this file to assign appropriate resource names, method names, and SQL verbs. -
Updating Existing Mappings: If a mapping file already exists, the tool will:
- Load the existing mappings
- Identify new operations that aren't yet mapped
- Flag operations with incomplete mappings (missing resource, method, or SQL verb)
- Skip operations that are already fully mapped
Update the resultant provider-dev/config/all_services.csv to add the stackql_resource_name, stackql_method_name, stackql_verb values for each operation.
This step transforms the split OpenAPI service specs into a fully-functional StackQL provider by applying the resource and method mappings defined in your CSV file.
npm run generate-provider -- \
--provider-name okta \
--input-dir provider-dev/source \
--output-dir provider-dev/openapi/src/okta \
--config-path provider-dev/config/all_services.csv \
--servers '[{"url": "https://{subdomain}.okta.com/", "variables": {"subdomain": {"default": "my-org","description": "The domain of your organization. This can be a provided subdomain of an official okta domain (okta.com, oktapreview.com, etc) or one of your configured custom domains."}}}]' \
--provider-config '{"auth": {"credentialsenvvar": "OKTA_API_TOKEN","type": "api_key","valuePrefix": "SSWS "}}' \
--skip-files _well_known.yaml \
--overwriteMake necessary updates to the output docs:
sh provider-dev/scripts/post_processing.shThe --servers parameter defines the base URL pattern for API requests, with variables that users can customize. For Okta, this allows specifying different subdomains for different Okta instances.
The --provider-config parameter sets up the authentication method. For Okta, this configures an API token authentication scheme that:
- Looks for the API token in the
OKTA_API_TOKENenvironment variable - Applies the
SSWSprefix required by Okta's API - Uses the token as an API key in the Authorization header
The generated provider will be structured according to the StackQL conventions, with properly organized resources and methods that map to the underlying API operations.
After running this command, you'll have a complete provider structure in the provider-dev/openapi/src directory, ready for testing or packaging.
Before running tests, start a StackQL server with your provider:
PROVIDER_REGISTRY_ROOT_DIR="$(pwd)/provider-dev/openapi"
npm run start-server -- --provider okta --registry $PROVIDER_REGISTRY_ROOT_DIRTest all metadata routes (services, resources, methods) in the provider:
npm run test-meta-routes -- okta --verboseWhen you're done testing, stop the StackQL server:
npm run stop-serveruse this command to view the server status:
npm run server-statusRun some test queries against the provider using the stackql shell:
PROVIDER_REGISTRY_ROOT_DIR="$(pwd)/provider-dev/openapi"
REG_STR='{"url": "file://'${PROVIDER_REGISTRY_ROOT_DIR}'", "localDocRoot": "'${PROVIDER_REGISTRY_ROOT_DIR}'", "verifyConfig": {"nopVerify": true}}'
./stackql shell --registry="${REG_STR}"To publish the provider push the okta dir to providers/src in a feature branch of the stackql-provider-registry. Follow the registry release flow.
Launch the StackQL shell:
export DEV_REG="{ \"url\": \"https://registry-dev.stackql.app/providers\", \"verifyConfig\": { \"nopVerify\": true }}"
./stackql --registry="${DEV_REG}" shellpull the latest dev okta provider:
registry pull okta;Run some test queries, for example...
SELECT
id,
activated,
created,
lastLogin,
lastUpdated,
passwordChanged,
JSON_EXTRACT(profile, '$.email') as email,
JSON_EXTRACT(profile, '$.firstName') as first_name,
JSON_EXTRACT(profile, '$.lastName') as last_name,
status,
statusChanged
FROM okta.users.users
WHERE subdomain = 'your-subdomain';npm run generate-docs -- \
--provider-name okta \
--provider-dir ./provider-dev/openapi/src/okta/v00.00.00000 \
--output-dir ./website \
--provider-data-dir ./provider-dev/docgen/provider-datacd website
# test build
yarn build
# run local dev server
yarn startUnder Pages in the repository, in the Build and deployment section select GitHub Actions as the Source. In Netlify DNS create the following records:
| Source Domain | Record Type | Target |
|---|---|---|
| okta-provider.stackql.io | CNAME | stackql.github.io |
MIT
Contributions to the Okta provider are welcome! Please feel free to submit a Pull Request.