Authenticate to EPM API via SAML? Looking for some working example code.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Welcome Idira to LIVEcommunity!

Our community just got stronger! Explore new identity security resources, connect with experts, and discover more ways to learn and collaborate.

Meet Idira

Authenticate to EPM API via SAML? Looking for some working example code.

L3 Networker

I have been trying to authenticate to the EPM API via SAML (CyberArk doc link: SAML authentication | CyberArk Docs). I believe I am following all of the steps correctly, right URL, parameters, HTTP method, etc. But for some reason no matter what I keep receiving an error. Does anyone have a working postman collection/code that achieves this?

11 REPLIES 11

L3 Networker

Hi @Ryan Kuczer​ ,

 

What is the exact error you’re receiving, and more importantly, how exactly are you generating the SAMLResponse used in the API call body?

 

 

Eviatar

L3 Networker

Hi @Eviatar David​ ,

 

Thank you for getting back to me so quickly.

 

Exact Error: {"StatusCode":401,"Error":"Authentication is required and has failed or has not yet been provided"}

 

To produce the SAMLResponse, I am using browser dev tools to monitor incoming data after signing in with SAML:

  • Navigating to my EPM's sign in page with SAML (https://login.epm.cyberark.com/SAML/REDACTED)
  • Perform SAML sign in with Microsoft with MFA
  • Looking for the POST request to my EPM's Assertion Consumer Service (https://login.epm.cyberark.com/SAML/acsu)
  • Grabbing the SAMLResponse token (in BASE64)
  • Then with the SAMLResponse create a POST request to https://login.epm.cyberark.com/SAML/Logon in Postman
    • Header is, Content-Type: application/x-www-form-urlencoded
    • Body (in x-www-form-urlencoded) has 2 key value pairs. 1. Key - SAMLResponse 2. Value - SAMLResponse token (base64)

 

Let me know if any other information is needed please. Thank you again for getting back to me

L3 Networker

Hi @Ryan Kuczer​ ,

 

This error usually indicates an issue with your SAMLResponse, most likely due to the way it was captured from the browser.

If you are using Azure as your IdP, there is an external PowerShell script that can help you obtain the SAMLResponse directly from Azure.

 

Please note that this is NOT an official CyberArk solution and is neither developed nor supported by CyberArk.

getSAMLResponse-Interactive/PowerShell New-SAMLInteractive Module at main · allynl93/getSAMLResponse...

 

let me know once you’ve tested it and if you were able to authenticate using this method.

 

 

Eviatar

 

 

L3 Networker

Hi @Eviatar David​ ,

 

Running into an issue with this method as it is automatically logging me in the embedded browser with my workstation's account that is not configured to access the EPM app. Looking for a workaround at the moment will update you.

L7 Applicator

HI @Ryan Kuczer​ 

 

It suggests that when a PowerShell session or any browser control running on Windows hits a resource configured for IdP, it attempts to pass your current Windows credentials.

 

Please try to use Use the -DisableAuthPrompt flag or If -DisableAuthPrompt doesn't work, you may need to trick the IdP's login flow to bypass integrated Windows authentication.

 

Hope it helps !

L3 Networker

@Malhar Vora​ - Thank you that does help, however that flag mentioned (-DisableAuthprompt) does not work for the referenced Powershell module in the GitHub Repo as it is a little older. I must download the project from source code and alter it to work with EPM instead of PVWA and build it again.

 

Can I instead use browser tools to do this instead? I did this initially, but it did not seem to work with the response included from my brower.

L7 Applicator

Hi @Ryan Kuczer​ 

 

Yes you can use the browser.

 

Please note token has a time limit. So you must use it almost immediately after capturing it.

 

Please see the following video

 

https://youtu.be/pNQUc5WKKWQ?si=ja8xInHNLba5t9Jf

 

Hope it helps !

Hi @Malhar Vora​ 

 

I appreciate you getting back to me, in the video Joe uses the same GetSamlResponse.exe that is configured for the PVWA. I am trying to initiate SAML auth with CyberArk EPM however, requiring me to rewrite the source code of the project. When I have time I will get to it. Just to recap, so far I have tried using:

 

  1. browser dev tools (SAML Response in base64), response = 401
  2. PowerShell module (getSamlresponse), doesn't work as I need to disable auto login as the account signed in on my machine is not configured with EPM access. Since it's an older PowerShell module it doesn't support disabling the auth prompt
  3. Using the modern webview2 exe doesn't work as it is configured for the PVWA so it doesn't capture anything logging into EPM. Hence needing to rewrite the source code and rebuilding the application.

 

Appreciate all the help Malhar!

L3 Networker

Hi @Ryan Kuczer​ ,

 

Is the IDP using Windows Integrated Authentication (Kerberos/NTLM)? If so, the browser automatically sends your Windows credentials without prompting, and i dont think modify the script will help.

 

Can you tell me what happens when the form opens? Does it:

-Automatically log you in without showing a login form?

-Show a login form but with fields pre-filled?

-Something else?

 

 

Eviatar

 

 

 

Hi @Eviatar David​ ,

 

PowerShell module - Automatically logs me in with the same credentials currently signed in on my machine then denies access. Which does not have access to the CyberArk EPM application.

 

New Webview2 Exe - Lets me login with the account of my choosing. However it is configured to only capture the response from the PVWA SAML hence the quote in the GitHub Repo: You can also download the pre-built binary. This is built specifically with the CyberArk API in mind, for other apps you will need to download from source and build.

It does not show a login for with pre-filled fields, I have not option to stop the process or cancel it.

  • 281 Views
  • 11 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

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!