- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
10-25-2022 09:29 AM
There are numerous examples and scripts for API-based SAML authentication to various apps, but none of these methods appear to work for SaaS EPM.
We're currently able to retrieve our token using the PS-SAML-Interactive method so many others use on other products, but we're *apparently* unable to send that token back in a way that is accepted, and we get:
{"StatusCode":401,"Error":"Authentication is required and has failed or has not yet been provided"}
Documentation says that the message should be formatted:
Key: "SAMLResponse"
Value: <IDPToken>
And sent to DISPATCHER.
https://<EPM_Server>/SAML/Logon
And we are sending as:
application/x-www-form-urlencoded
Can anyone demonstrate working SAML auth to EPM SaaS? Our scripts currently use EPM auth, which we reserve for our "Break Glass" account management. Best practice has all user accounts using SAML.
11-14-2022 04:30 AM
Hi @Matthew Stenger ,
Have you found the solution?
I am in the same situation
Thank you and best regards
11-16-2022 09:45 AM
I have tested this in my lab and was able to get an Authentication Result from EPM utilizing the following GitHub library for the "Get-SAMLToken" function referenced in the script below.
https://github.com/allynl93/PS-SAML-Interactive
$DispatcherURL = "https://login.epm.cyberark.com/SAML/Logon"
$Method = "POST"
$Headers = @{"Content-Type" = "application/x-www-form-urlencoded"}
$SAMLResponse = Get-SAMLToken -LoginIDP "https://YOUR_IDP_Logon_URL"
$SAMLAuthBody = @{SAMLResponse= "$SAMLResponse"}
$SAMLAuthResponse = Invoke-RestMethod -Uri $DispatcherURL -Method $Method -Headers $Headers -Body $SAMLAuthBody
11-18-2022 08:41 AM
We figured this out. Biggest trick was getting the right response from the right redirected URL in the SAML chain and making sure it's formatted right. Eric's code above sorta illustrates that with the YOUR_IDP_Logon_URL
I hate to tease, but I've asked the other engineer on my team who did the heavy lifting to make a post explaining all the gotchas one he's fully confident of his code.
I just didn't want people to give up hope in the meantime.
10-28-2024 04:40 AM
Any updates on this ?
10-28-2024 11:16 AM
https://www.youtube.com/watch?v=Sq-cwn_1lvk The link in this guys video for postman is pretty good for testing SAML.
10-28-2024 11:16 AM
https://www.youtube.com/watch?v=Sq-cwn_1lvk The link in this guys video for postman is pretty good for testing SAML.
05-08-2025 10:39 PM
Hi @Milan Minchev, @Matthew Stenger, @Eric Vanatta,
We are facing a similar issue, when we copy the SAML response from ACSU URL from browser tools, the token when passed to
https://login.epm.cyberark.com/SAML/Logon, gives
{"StatusCode":401,"Error":"Authentication is required and has failed or has not yet been provided"}
Could you guide?
09-30-2025 10:22 AM
@Matthew Stenger - I don't know if you are still active here and I know its been 3 years since. But was there any update to this potentially.
09-30-2025 10:37 AM
Let me try and rehash this again. The first thing you will need is the SAML response from your IDP session. The response should look something like the following:
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="_exampleResponseID" Version="2.0" IssueInstant="2024-10-29T20:31:08Z" Destination="https://yourapp.com/saml/SSO/alias/defaultAlias">
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">https://idp.example.com</saml:Issuer>
<samlp:Status>
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
</samlp:Status>
<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_exampleAssertionID" IssueInstant="2024-10-29T20:31:08Z" Version="2.0">
<saml:Issuer>https://idp.example.com</saml:Issuer>
<saml:Subject>
<saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">[email protected]</saml:NameID>
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData NotOnOrAfter="2024-10-29T21:31:08Z" Recipient="https://yourapp.com/saml/SSO/alias/defaultAlias"/>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Conditions NotBefore="2024-10-29T20:31:08Z" NotOnOrAfter="2024-10-29T21:31:08Z">
<saml:AudienceRestriction>
<saml:Audience>https://yourapp.com</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
<saml:AuthnStatement AuthnInstant="2024-10-29T20:31:08Z" SessionIndex="_exampleSessionIndex">
<saml:AuthnContext>
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
</saml:Assertion>
</samlp:Response>Once you have your response captured you will need to convert this response into BASE64: You can do this via PowerShell like this. I would first store the xml data into a variable to make it easier.
$xml = @'
<SAML RESPONSE GOES HERE>
'@
$base64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($xml))Once you have the base64 response you might need to convert any html codes for '=' or '+' to the actual '=' and '+' symbols. replace "+" with "+". and "=" with "="
Then finally in your PowerShell Script you need to create the Body variable for the authentication request.
$Body = @{SAMLResponse= "$SAMLResponse"}I hope this helps.
Here is an example of the full script:
# PowerShell script to log in to EPM via SAML using REST API
# Configuration
$epmServer = "https://<EPM_Server>"
$xml = @"
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="_exampleResponseID" Version="2.0" IssueInstant="2024-10-29T20:31:08Z" Destination="https://yourapp.com/saml/SSO/alias/defaultAlias">
<saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">https://idp.example.com</saml:Issuer>
<samlp:Status>
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
</samlp:Status>
<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_exampleAssertionID" IssueInstant="2024-10-29T20:31:08Z" Version="2.0">
<saml:Issuer>https://idp.example.com</saml:Issuer>
<saml:Subject>
<saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">[email protected]</saml:NameID>
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData NotOnOrAfter="2024-10-29T21:31:08Z" Recipient="https://yourapp.com/saml/SSO/alias/defaultAlias"/>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Conditions NotBefore="2024-10-29T20:31:08Z" NotOnOrAfter="2024-10-29T21:31:08Z">
<saml:AudienceRestriction>
<saml:Audience>https://yourapp.com</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
<saml:AuthnStatement AuthnInstant="2024-10-29T20:31:08Z" SessionIndex="_exampleSessionIndex">
<saml:AuthnContext>
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
</saml:Assertion>
</samlp:Response>
"@
# Encode SAML response to Base64
$encodedSamlResponse = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($samlResponse))
# API endpoint
$uri = "$epmServer/SAML/Logon"
# Headers
$headers = @{
"Content-Type" = "application/x-www-form-urlencoded"
}
# Body
$body = "SAMLResponse=$encodedSamlResponse"
try {
# Make POST request
$response = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body
# Output response
$response | ConvertTo-Json
}
catch {
Write-Error "Error: $_"
}
09-30-2025 11:56 AM
Hi Eric, this helps. But is there any other option if i cannot run the powershell script? I have a account I am logged into on my endpoint that is not provisioned to access EPM via SAML/SSO?
I can verify I have the correct token from the browser which is the same after converting from base64 etc... But in postman or python I am still receiving the error {"StatusCode":401,"Error":"Authentication is required and has failed or has not yet been provided"}
09-30-2025 12:03 PM
To clarify there is no way for me to override the auto-sign in attempt in the embedded browser with the incorrect account. Which gives me an error. Without breaking company policy I cannot run the script correctly.
09-30-2025 12:12 PM
The userid in the SAML response must be able to log into EPM. If you can log in via username and password you should be able to log in via SAML if it is configured in the EPM tenant.
09-30-2025 12:48 PM
Hi Eric, thanks for getting back to me.
The user id logging into SAML is able to log into EPM. The account my PC is signed into when running the script is different, which does not have access to EPM.
My account that logins in EPM is able to have a password set even if I login via SSO. But then I am prompted for email verification with the username/password combination, the issue is that I do not have a mailbox attached to this secondary login.
I know this is a special case, let me know if there is any way to disable that email verification for myself.
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!

