# Retrieving a session cookie via OpenID

**URL:** <https://devforum.okta.com/t/retrieving-a-session-cookie-via-openid/1068>\
**Category:** OAuth/OIDC\
**Created:** [January 17, 2018, 6:37pm UTC](https://devforum.okta.com/t/retrieving-a-session-cookie-via-openid/1068 "2018-01-17T18:37:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert01](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Robert01](https://devforum.okta.com/u/Robert01)\
**Post date:** [January 17, 2018, 6:37pm UTC](https://devforum.okta.com/t/retrieving-a-session-cookie-via-openid/1068/1 "2018-01-17T18:37:11Z")

</div>

Hi All,

I am currently using the “ **Authentication API** ” to request a token using

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“http…”);

which then provides me with a token. Then I proceed to create a HttpClient request to

HttpClient client = new HttpClient();  
client.DefaultRequestHeaders.Add(“Accept”, “_/_”);  
HttpResponseMessage responseSession = await client.GetAsync(“[https://dev-xxxxx.oktapreview.com/oauth2/v1/authorize?client\_id=xxxxxxxxxx&response\_type=id\_token&scope=openid&prompt=none&redirect\_uri=http://xxxxxxxxxxxxxx.net&state=Af0ifjslDkj&nonce=n-0S6\_WzA2Mj&sessionToken=](https://dev-xxxxx.oktapreview.com/oauth2/v1/authorize?client_id=xxxxxxxxxx&response_type=id_token&scope=openid&prompt=none&redirect_uri=http://xxxxxxxxxxxxxx.net&state=Af0ifjslDkj&nonce=n-0S6_WzA2Mj&sessionToken=)” + token);

but I keep getting 404 response.

I am following instructions from: [Work with Okta session cookies | Okta Developer](https://developer.okta.com/use_cases/authentication/session_cookie#retrieving-a-session-cookie-via-openid-connect-authorization-endpoint)

I have made sure that the redirect\_uri is within “Trusted Origins”.

Any ideas on what I could be doing wrong?

Many thanks!

---

<div class="post-metadata">

**Author:** ![lboyette](https://avatars.discourse-cdn.com/v4/letter/l/87869e/32.png) [@lboyette](https://devforum.okta.com/u/lboyette)\
**Post date:** [January 18, 2018, 1:28am UTC](https://devforum.okta.com/t/retrieving-a-session-cookie-via-openid/1068/2 "2018-01-18T01:28:37Z")

</div>

Hey @Robert01, thanks for posting. I’m trying to figure out exactly what you’re trying to do.

There are a couple ways you can configure authentication:

1. You set your own cookie
2. You accept `access_token`s sent by the user’s browser

If 1, you let the server start the redirect using a .NET OpenID Connect library (your user’s browser is redirected, then your server parses the results on the redirect uri). These libraries do correct validation for you, so you’ll just get the user info and store it in your own cookie. This is the **authorization code flow**.

If 2, you let the browser start the redirect (you could use `okta-auth-js` for this) to get an `access_token`. The browser is then expected to send that `access_token` in every request to your server. Each endpoint on your server should validate any `access_token` sent. This is the **implicit flow**.

---

<div class="post-metadata">

**Author:** ![Robert01](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Robert01](https://devforum.okta.com/u/Robert01)\
**Post date:** [January 18, 2018, 4:14pm UTC](https://devforum.okta.com/t/retrieving-a-session-cookie-via-openid/1068/3 "2018-01-18T16:14:08Z")

</div>

Hi @lboyette, I am using the Okta authentication API to make a HTTP request with the username and password and obtaining an access token. From there, I followed the documents from Okta, to retrieve a session cookie via OpenID Connect Authorization Endpoint.

Reason why I am doing that is because we want to use our own custom login portal, and have the API just authenticate and create the Session cookie and then use that session cookie to literally login the user.

In regards to the scenario 1, does the parsed results in the redirect uri, need to have some code to receive the session?

I am currently using [ASP.NET](http://ASP.NET) 4.6.x.

---

<div class="post-metadata">

**Author:** ![tom](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/tom/32/24_2.png) [@tom](https://devforum.okta.com/u/tom)\
**Post date:** [January 18, 2018, 5:30pm UTC](https://devforum.okta.com/t/retrieving-a-session-cookie-via-openid/1068/4 "2018-01-18T17:30:42Z")

</div>

When you say:

> literally login the user

Are you talking about getting the user to the end-user chiclet page?

---

<div class="post-metadata">

**Author:** ![Robert01](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Robert01](https://devforum.okta.com/u/Robert01)\
**Post date:** [January 18, 2018, 5:48pm UTC](https://devforum.okta.com/t/retrieving-a-session-cookie-via-openid/1068/5 "2018-01-18T17:48:08Z")

</div>

Hi Tom,

Which is the end-user chiclet page?

---

<div class="post-metadata">

**Author:** ![tom](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/tom/32/24_2.png) [@tom](https://devforum.okta.com/u/tom)\
**Post date:** [January 18, 2018, 7:04pm UTC](https://devforum.okta.com/t/retrieving-a-session-cookie-via-openid/1068/6 "2018-01-18T19:04:41Z")

</div>

This thing:

 ![Single_Sign-On __SSO__ -_Identity_Access_Management___Okta](https://global.discourse-cdn.com/oktadev/original/1X/93692736dfedc38f288e8d9fff1216036d8cb8a5.png)

---

<div class="post-metadata">

**Author:** ![jaynishp](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@jaynishp](https://devforum.okta.com/u/jaynishp)\
**Post date:** [October 22, 2019, 2:33pm UTC](https://devforum.okta.com/t/retrieving-a-session-cookie-via-openid/1068/7 "2019-10-22T14:33:16Z")

</div>

Hi Robert,  
I read your comments and need your help if you can.  
We are using the same approach by calling the Authentication API to authenticate the user using Username and Password. But after that when we are stuck in creating the cookie in user’s browser using OpenID Connect Authorization Endpoint method.  
Can you please share the code for how can we achieve that?

Thank you very much in advance.

---

<div class="post-metadata">

**Author:** ![dragos](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/dragos/32/1313_2.png) [@dragos](https://devforum.okta.com/u/dragos)\
**Post date:** [October 23, 2019, 3:23am UTC](https://devforum.okta.com/t/retrieving-a-session-cookie-via-openid/1068/8 "2019-10-23T03:23:29Z")

</div>

Hi @jaynishp

Please check out [this document](https://developer.okta.com/docs/guides/session-cookie/overview/). In short, you would need to take the sessionToken from the response from /api/v1/authn and pass it in the browser to open a session in Okta.

---

<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:** [January 24, 2024, 6:36pm UTC](https://devforum.okta.com/t/retrieving-a-session-cookie-via-openid/1068/9 "2024-01-24T18:36:47Z")

</div>

Closed on January 24, 2024, 6:36pm UTC


