# Accessing okta protected URL from linux shell

**URL:** <https://devforum.okta.com/t/accessing-okta-protected-url-from-linux-shell/19839>\
**Category:** Questions\
**Created:** [March 16, 2022, 3:19pm UTC](https://devforum.okta.com/t/accessing-okta-protected-url-from-linux-shell/19839 "2022-03-16T15:19:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvandesteeg](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@bvandesteeg](https://devforum.okta.com/u/bvandesteeg)\
**Post date:** [March 16, 2022, 3:19pm UTC](https://devforum.okta.com/t/accessing-okta-protected-url-from-linux-shell/19839/1 "2022-03-16T15:19:53Z")

</div>

Hi all,

This has probably been asked 1000 times but I cannot find a good example of how to curl an okta protected URL.

I have the okta\_authn\_mfa.sh script and it works, showing me stateToken, sessionToken and sessionId.

Next step is the tricky one: using one of the Tokens and/or sessionId in a redirectURL. I tried something like this:

curl https://{okta-url}/login/sessionCookieRedirect?token={sessionToken from okta\_authn\_mfa.sh}&redirectUrl={redirect URL}  
…but getting a “Bad request” back.

Can someone point me in the good direction? With example if possible 😉

---

<div class="post-metadata">

**Author:** ![louie](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@louie](https://devforum.okta.com/u/louie)\
**Post date:** [March 17, 2022, 6:12pm UTC](https://devforum.okta.com/t/accessing-okta-protected-url-from-linux-shell/19839/2 "2022-03-17T18:12:48Z")

</div>

Are you receiving any additional information in the 400 Bad Request error?

---

<div class="post-metadata">

**Author:** ![bvandesteeg](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@bvandesteeg](https://devforum.okta.com/u/bvandesteeg)\
**Post date:** [March 18, 2022, 7:25am UTC](https://devforum.okta.com/t/accessing-okta-protected-url-from-linux-shell/19839/3 "2022-03-18T07:25:07Z")

</div>

Hi @louie and thanks for responding. This is the result the okta\_auth shell script:

./okta\_authn\_mfa.sh -u bvandesteeg -o \*\*\*\*\*\*\*\*\*\*\*\*\*\* Enter Password for bvandesteeg on https://\*\*\*\*\*\*\*\*\*\*\*\*.okta-emea.com:

Doing primary authentication…  
Congratulations! You got a stateToken: 00OhQ8\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*d0rIcWA\_R6x. That’s used in a multi-step authentication flow, like MFA.

Sending Okta Verify push notification…  
Polling for push approve…  
Polling for push approve…  
Congratulations! You got a sessionToken: 201113\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*-2RyOpILL8yMW-\_. That will be exchanged for a sessionId next.  
Exchanging sessionToken for sessionId…  
Congratulations! You’ve established a session with https://\*\*\*\*\*\*\*\*\*\*\*\*\*.okta-emea.com. Here’s your sessionId: 1027yjQl\*\*\*\*\*\*\*\*\*\*\*\*\*\*0A

Then the curl action:

\<html\>  
\<head\>  
\<meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8”\>  
\<meta name=“viewport” content=“width=device-width, initial-scale=1.0” /\>  
\<meta name=“robots” content=“noindex,nofollow” /\>  
\<title\>\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* - Bad Request  
\<link rel=“stylesheet” type=“text/css” href="/assets/css/sections/errors-v2.css"\>  
\<!-- Styles generated from theme →   
\<link href="/api/internal/brand/theme/style-sheet?touch-point=ERROR\_PAGE&v=1c27\*\*\*\*\*\*\*\*\*\b5050be" rel=“stylesheet” type=“text/css”\>  
\<!-- Favicon from theme →   
\<link rel=“shortcut icon” href="/favicon.ico" type=“image/x-icon”/\>  
\</head\>  
\<body\>  
\<div class=“login-bg-image tb–background” style=“background-image: url(‘https://eu\*\*\*\*\*\*\*\*\*\*\*\*.com/fs/bco/7/fs0j0\*\*\*\*\*\*\*l0i6’)”\>  
\<div class=“widget”\>  
\<div class=“container”\>  
\<div class=“header”\>  
\<img alt="\*\*\*\*\*\*\*\*\*\*" src=“https://\*\*\*\*\*\*\*\*\*.com/fs/bco/1/fs0\*\*\*\*\*\*\*\*\*7” class=“org-logo”\>  
\</div\>  
\<div class=“illustration”\>  
\<!-- Show HTTP error code if exists →   
\<div class=“error-code”\>400  
\<!-- Show generic error image if not →   
\</div\>  
\<div class=“content”\>  
\<h2 class=“o-form-title”\>Bad Request  
\<p class=“o-form-explain”\>Your request resulted in an error.

  
\<a href="/" class=“button tb–button”\>Go to Homepage  
\</div\>  
\</div\>  
\</div\>  
\</body\>  
\</html\>NONE

It does not matter if I used the stateToken, sessionToken or sessionId. In all cases I get the same. Also the prompt is not being returned. I have to give an enter or ctrl-c.

Any clue?

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [February 12, 2024, 6:17pm UTC](https://devforum.okta.com/t/accessing-okta-protected-url-from-linux-shell/19839/4 "2024-02-12T18:17:44Z")

</div>

Closed on February 12, 2024, 6:17pm UTC


