How to obtain an OIDC access token using Powershell

Follow
    Applies to:
  • Legacy SecureAuth IdP
Deployment model:
  • On Premises
  • SecureAuth IdP Version Affected:  All

     

    Description: 

    How to obtain an OIDC access token using Powershell

     

    Cause

     

    N/A

     

    Resolution

    Change the value for $Url, username, password, client_id and secret to suit.

    $Url = "https://IdP_FQDN/secureauth123/oidctoken.aspx"
    $Body = @{
    username = "user1"
    password = "Pa$$w0rd1"
    grant_type="password"
    scope="openid offline_access"
    client_id="6e05242ca1564374b556c0edb9439bc1"
    client_secret="2072ce54d2af30bf04833ce598383357ca572a53fe4282cbab5cbaf51964bd45"
    }

    $response = ''
    $idToken = ''
    $paddedIdToken = ''
    $results = ''

    $response = Invoke-RestMethod -Method Post -Uri $url -Body $body -UseDefaultCredentials
    $idToken = ($response.id_token.Split(".")[1] -replace "-", "+" -replace "_", "/")
    $paddedIdToken = $idToken.PadRight($idToken.Length + (4 - $idToken.Length % 4) % 4,"=")

    $results = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($paddedIdToken)) | ConvertFrom-Json

     

    For more information and examples using Postman see this article:

    https://support.secureauth.com/hc/en-us/articles/360019647072-How-to-use-Oidctoken-aspx-with-Postman

     

     

     

    SecureAuth Knowledge Base Articles provide information based on specific use cases and may not apply to all appliances or configurations. Be advised that these instructions could cause harm to the environment if not followed correctly or if they do not apply to the current use case.

    Customers are responsible for their own due diligence prior to utilizing this information and agree that SecureAuth is not liable for any issues caused by misconfiguration directly or indirectly related to SecureAuth products.

    0 out of 0 found this helpful

    Comments

    0 comments

    Please sign in to leave a comment.