9

I'm trying to use curl to log into an Okta-enabled site providing the user name & password using the parameter -u {username:password} and all I get back is the html content of the Okta redirect page. How can I login into the app by providing my Okta credentials using curl?

nsierraj
  • 111
  • 1
  • 5

1 Answers1

6

You can use the following script, assuming you have installed jq (https://stedolan.github.io/jq/download):

sessionToken=$(curl -X POST -H "Accept: application/json" -H "Content-Type:
application/json" -d '{
"username": "[okta_username]",
"password": "[password]",
"options": {
"multiOptionalFactorEnroll": true,
 "warnBeforePasswordExpired": true
}  
}' "https://[yourorg].oktapreview.com/api/v1/authn" | jq '.sessionToken' -r)

 curl -X GET "https://[yourorg].oktapreview.com/login/sessionCookieRedirect?token=${sessionToken}&redirectUrl=http://blah" -c "okta-cookie"

 curl -X GET [OKTA_EMBED_LINK] -b "okta-cookie" -L -v

From the last line, you will need to grab the SAMLResponse form parameter and submit it to the action url of the same form.

I hope this helps!

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Raphael Londner
  • 512
  • 2
  • 5
  • Is there any other way that doesn't require you to request a url that has /api/v1/authn in it? If I query that one using a web browser I get E0000022: The endpoint does not support the provided HTTP method which suggests that my org doesn't support it. – Giuseppe Salvatore Jan 02 '19 at 15:03
  • @Giuseppe that's because in the browser you are doing a GET and the endpoint requires POST – danielpops Apr 24 '19 at 19:28
  • 5
    How to grab and submit the SAMLResponse form parameter in the last line? Could you provide a little more detail? – shortcipher3 Mar 16 '21 at 15:20
  • 1
    I found that my curl call would result in an error of "The request body was not well-formed. (E0000003). With some experimentation, I realised that was rejecting my request due to those extra padding spaces and carriage returns within the -d'...' argument. Once I removed them (e.g., `-d'{"username":"name","password":"pwd",etc}'`), my curl call was successful. – Gurce Jun 24 '23 at 14:12