How-To (CM-SaaS): Setup custom API integration service account with Okta

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


  1. Setup Okta:
    1. Go to Applications and Resources > Applications > Create App Integration.
    2. Choose API Services > Next > Name your app > select Use Okta-generated client ID > Save.
    3. Go to General Settings > Edit > Uncheck Require Demonstrating Proof of Possession (DPoP).
    4. Keep note of your client ID and client secret.
    5. Go to Security > API > Authorization Servers > Default > Take note of the Issuer URL and audience.
    6. Go to Access Policies > Add Policy > Set name and description > Assigned to All clients > Create Policy.
    7. Add rule > Use defaults > Save.
    8. Go to Scopes > Add Scope > Set name "custom_scope" > Include in public metadata > Create.
    9. You should now be able to request a JWT token from Okta.
  2. Request JWT from Okta:
    1. Use the example PowerShell script to request a JWT.
    2. ############## 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
          }
      }
  3. Create the service account:
    1. Go to CM-SaaS > Settings > Service Accounts > New > Custom API Integration > Set name > Set owning team > Set application > Continue.
    2. Set the Issuer URL (Issuer URL from step #1e).
    3. Set the JKS URI:  (<Issuer URL>/v1/keys).
    4. Set Subject Identifier (Client ID from step 1d).
    5. Set Audience (Audience value from step 1e).
  4. Request a CM-SaaS token:
    1. Using your JWT, you can now request API tokens. See example script.
    2. ############## 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
  5. Test your service account API token:
    1. See this example script which makes a certificate request using the supplied token.
    2. ############## 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
          }
      }
  6. Process complete.


Actions
  • Print
  • Copy Link

    https://knowledgebase.paloaltonetworks.com/KCSArticleDetail?id=kA1hj0000001JyJCAU&lang=en_US&refURL=http%3A%2F%2Fknowledgebase.paloaltonetworks.com%2FKCSArticleDetail