# Problem with customizing redirect\_uri

**URL:** <https://devforum.okta.com/t/problem-with-customizing-redirect-uri/4077>\
**Category:** Questions\
**Created:** [January 30, 2019, 1:52am UTC](https://devforum.okta.com/t/problem-with-customizing-redirect-uri/4077 "2019-01-30T01:52:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kleinbiker](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@kleinbiker](https://devforum.okta.com/u/kleinbiker)\
**Post date:** [January 30, 2019, 1:52am UTC](https://devforum.okta.com/t/problem-with-customizing-redirect-uri/4077/1 "2019-01-30T01:52:15Z")

</div>

I am using OpenId Connect. When a user navigates to some Url in our app, after the login we want the user to get redirected back to the original Url they navigated to.

For doing that, I tried the following - it’s also described at [stackoverflow](https://stackoverflow.com/questions/30645178/owin-openidconnect-middleware-set-redirecturi-dynamically).

Notifications = new OpenIdConnectAuthenticationNotifications  
{  
RedirectToIdentityProvider = async n =\>  
{  
n.ProtocolMessage.RedirectUri =  
String.Format("{0}?ReturnUrl={1}", \_oktaRedirectUrl, HttpUtility.UrlEncode(n.OwinContext.Request.Uri.ToString()));  
},  
…

In the above, \_oktaRedirectUrl is the Uri that is whitelisted in the client app settings.

When I run this I get the following error from Okta:

## Error Code: invalid\_request

## Description: The ‘redirect\_uri’ parameter must be an absolute URI that is whitelisted in the client app settings.

Any suggestions on resolving the above problem or some other way of implementing it? Thx.

---

<div class="post-metadata">

**Author:** ![micah.silverman](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/micah.silverman/32/1239_2.png) [@micah.silverman](https://devforum.okta.com/u/micah.silverman)\
**Post date:** [January 30, 2019, 2:41pm UTC](https://devforum.okta.com/t/problem-with-customizing-redirect-uri/4077/2 "2019-01-30T14:41:24Z")

</div>

The redirect uri must not have dynamic query string parameters on it per the OAuth specification to guard against tampering by attackers. That’s why the redirect uri you define at Okta for whitelisting must be absolute.

There is a technique to use the state parameter to carry csrf protection (its intended propose) as well as additional information (like where to send the user after the redirection) using jwts.

This approach is outlined here: [https://tools.ietf.org/html/draft-bradley-oauth-jwt-encoded-state-09](https://tools.ietf.org/html/draft-bradley-oauth-jwt-encoded-state-09)

---

<div class="post-metadata">

**Author:** ![kleinbiker](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@kleinbiker](https://devforum.okta.com/u/kleinbiker)\
**Post date:** [January 31, 2019, 5:18am UTC](https://devforum.okta.com/t/problem-with-customizing-redirect-uri/4077/3 "2019-01-31T05:18:00Z")

</div>

Thanks for the link, that approach works.

---

<div class="post-metadata">

**Author:** ![jgruber](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jgruber](https://devforum.okta.com/u/jgruber)\
**Post date:** [May 22, 2019, 8:30pm UTC](https://devforum.okta.com/t/problem-with-customizing-redirect-uri/4077/5 "2019-05-22T20:30:27Z")

</div>

The Okta API doesn’t allow many characters in the state, so you can’t make the state a JWT. How can this OAuth approach be applied within the Okta implementation?

---

<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:** [November 11, 2020, 6:02pm UTC](https://devforum.okta.com/t/problem-with-customizing-redirect-uri/4077/6 "2020-11-11T18:02:52Z")

</div>

Closed on November 11, 2020, 6:02pm UTC


