How-To (CM-SaaS): Setup custom API integration service account with Okta
116
Created On 11/10/26 11:04 AM - Last Modified 11/19/26 20:15 PM
Objective
This article covers how to setup a custom API integration service account that is authenticated through Okta.
Environment
CM-SaaS
Procedure
- Setup Okta:
- Go to Applications and Resources > Applications > Create App Integration.
- Choose API Services > Next > Name your app > select Use Okta-generated client ID > Save.
- Go to General Settings > Edit > Uncheck Require Demonstrating Proof of Possession (DPoP).
- Keep note of your client ID and client secret.
- Go to Security > API > Authorization Servers > Default > Take note of the Issuer URL and audience.
- Go to Access Policies > Add Policy > Set name and description > Assigned to All clients > Create Policy.
- Add rule > Use defaults > Save.
- Go to Scopes > Add Scope > Set name "custom_scope" > Include in public metadata > Create.
- You should now be able to request a JWT token from Okta.
- Request JWT from Okta:
- Use the example PowerShell script to request a JWT.
-
############## Update these values to match your Okta settings ############## $oktaTokenUri = "<Issuer URL>/v1/token" # Use Issuer URL from step 1e $clientId = "<client-id>" # Client ID from step 1d $clientSecret = "<client-secret>" # Client secret from step 1d $scope = "<scope>" # Scope from step 1h # Base64 encode credentials for Basic Auth $authPair = "${clientId}:${clientSecret}" $authBytes = [System.Text.Encoding]::UTF8.GetBytes($authPair) $authBase64 = [Convert]::ToBase64String($authBytes) $headers = @{ "Authorization" = "Basic $authBase64" "Accept" = "application/json" } # Only grant_type and scope belong in the body when using Basic Auth $oktaBody = @{ grant_type = "client_credentials" scope = $scope } try { $oktaResponse = Invoke-RestMethod -Method Post ` -Uri $oktaTokenUri ` -Headers $headers ` -ContentType "application/x-www-form-urlencoded" ` -Body $oktaBody $oktaJwt = $oktaResponse.access_token Write-Host "Obtained Okta JWT successfully." -ForegroundColor Green } catch { Write-Error "Failed to obtain token: $_" if ($_.Exception.Response) { $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream()) Write-Host "Error Body: $($reader.ReadToEnd())" -ForegroundColor Red } }
- Create the service account:
- Go to CM-SaaS > Settings > Service Accounts > New > Custom API Integration > Set name > Set owning team > Set application > Continue.
- Set the Issuer URL (Issuer URL from step #1e).
- Set the JKS URI: (<Issuer URL>/v1/keys).
- Set Subject Identifier (Client ID from step 1d).
- Set Audience (Audience value from step 1e).
- Request a CM-SaaS token:
- Using your JWT, you can now request API tokens. See example script.
-
############## Update these values to match your environment settings ############## $venafiTokenUri = "<token-endpoint-url>" # Visible in the service account settings under Token Endpoint URL $oktaJwt = "<JWT-token>" # Use resulting JWT from step 2b # Encode client_credentials form payload $grantType = [System.Web.HttpUtility]::UrlEncode("client_credentials") $assertionType = [System.Web.HttpUtility]::UrlEncode("urn:ietf:params:oauth:client-assertion-type:jwt-bearer") $assertion = [System.Web.HttpUtility]::UrlEncode($oktaJwt) $formBody = "grant_type=$grantType&client_assertion_type=$assertionType&client_assertion=$assertion" try { $response = Invoke-RestMethod -Method Post ` -Uri $venafiTokenUri ` -ContentType "application/x-www-form-urlencoded" ` -Body $formBody -ErrorAction Stop } catch { Write-Host "Failed to invoke request: $($_.Exception.Message)" -ForegroundColor Red if ($_.Exception.Response) { $reader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream()) Write-Host "Error Body: $($reader.ReadToEnd())" -ForegroundColor DarkRed } return } $cmSaasToken = $response.access_token Write-Host "Obtained CM-SaaS Access Token successfully!" -ForegroundColor Green $cmSaasToken
- Test your service account API token:
- See this example script which makes a certificate request using the supplied token.
-
############## Update these values to match your CM-SaaS settings ############## $appId = "<application-id>" # Application ID for an application that is selected for the service account $templateId = "<template-id>" # Template ID that is assigned to your application $cmSaasToken = "<api-token>" # API token from step 4b $headers = @{ # Use your API token here for cmSaaSToken variable "Authorization" = "Bearer $cmSaasToken" "Content-Type" = "application/json" "Accept" = "application/json" } $body = @{ applicationId = $appId certificateIssuingTemplateId = $templateId isVaaSGenerated = $true csrAttributes = @{ commonName = "test55.example.com" subjectAlternativeNamesByType = @{ dnsNames = @("test.example.com") } } } | ConvertTo-Json -Depth 5 try { $requestResponse = Invoke-RestMethod -Method Post ` -Uri "https://api.venafi.cloud/outagedetection/v1/certificaterequests" ` -Headers $headers ` -Body $body Write-Host "Certificate Request Created Successfully!" -ForegroundColor Green $requestResponse } catch { Write-Error "Request failed: $_" if ($_.Exception.Response) { $reader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream()) Write-Host "Error Body: $($reader.ReadToEnd())" -ForegroundColor Red } }
- Process complete.