# Authorization code within Rules

**URL:** <https://community.auth0.com/t/authorization-code-within-rules/100929>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [February 21, 2023, 1:21pm UTC](https://community.auth0.com/t/authorization-code-within-rules/100929 "2023-02-21T13:21:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![userraj](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/userraj/32/42807_2.png) [@userraj](https://community.auth0.com/u/userraj)\
**Post date:** [February 21, 2023, 1:21pm UTC](https://community.auth0.com/t/authorization-code-within-rules/100929/1 "2023-02-21T13:21:33Z")

</div>

Hello upon successful authorization I am being redirected to my application’s allowed callback URL and a code parameter is being appended.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/1/2/1233f4171a0182b3b6c70971041d4e570adcd30f.png)

However when trying to redirect from within Rules using the context.redirect , the code parameter is no more appended, instead I am receiving the state parameter.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/a/9/a916dd33dbd1c34e6a75df3e38cd5a93c88a3392.png)

What do I need to configure to obtain the code parameter from within the Rules ?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [February 21, 2023, 9:58pm UTC](https://community.auth0.com/t/authorization-code-within-rules/100929/3 "2023-02-21T21:58:58Z")

</div>

Hi @userraj,

Welcome to the Auth0 Community!

Having looked closely at your screenshot, it appears that you have not resumed the authentication flow.

In this case, I recommend resuming flow by calling the `/continue` endpoint with the `state` you received when you were sent to the redirect URL.

For example:  
`https://{yourDomain}/continue?state={originalState}`

(Reference: [Redirect Users from Within Rules](https://auth0.com/docs/customize/rules/redirect-users#:~:text=To%20resume%20the%20authentication%20transaction%2C%20you%20would%20redirect%20to%3A))

After doing so, you will be redirected back to your callback URL with the code and state parameter in the URL (just as you see in the first screenshot).

Please let me know if you have any questions or need further clarification on this step.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![userraj](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/userraj/32/42807_2.png) [@userraj](https://community.auth0.com/u/userraj)\
**Post date:** [February 22, 2023, 4:51am UTC](https://community.auth0.com/t/authorization-code-within-rules/100929/4 "2023-02-22T04:51:27Z")

</div>

Hello @rueben.tiow , Much appreciate your response.  
I may have missed out elaborating why I am trying to redirect using Rules.

Actually there is a dynamic parameter (named navigate) that I need to add to the callbackURL and since wildcards do not allow me to do so in the allowed callbackurls I am adding the dynamic parameter from within the rules.

Allowed callback url : `https://{myDomain}/myAppMethod?client=xyz`

Overwriting callback url in rules : `https://{myDomain}/myAppMethod?client=xyz&navigate=*somethingDynamicHere*`

And what is desired is that auth0 hits back to my application with the format  
`https://{myDomain}/myAppMethod?client=xyz&navigate=*somethingDynamicHere*&code= ******** `

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [February 22, 2023, 10:44pm UTC](https://community.auth0.com/t/authorization-code-within-rules/100929/5 "2023-02-22T22:44:51Z")

</div>

Hi @userraj,

Thank you for your response and clarification.

> [@userraj](#):
>
> And what is desired is that auth0 hits back to my application with the format  
> `https://{myDomain}/myAppMethod?client=xyz&navigate=*somethingDynamicHere*&code= ******** `

Unfortunately, as you experienced, this is not possible with using Redirect Rules.

Generally, when performing a redirect using Rules, you must resume the authentication flow by sending the original state back to the `/continue` endpoint. If this is not done, Auth0 will lose the context of the login transaction, and the user will not be able to log in due to an `invalid_request` error. [Reference: [Redirect Users from Within Rules](https://auth0.com/docs/customize/rules/redirect-users?_gl=1*54vlvo*rollup_ga*NTcwODI4NzMwLjE2Mjk3NDgxMzk.*rollup_ga_F1G3E656YZ*MTY3NzA4ODk5NC4yNjkuMS4xNjc3MDkwMTA2LjU3LjAuMA..&_ga=2.53743777.849927141.1676908189-570828730.1629748139&_gac=1.154847690.1676341931.CjwKCAiA3KefBhByEiwAi2LDHHJfLY71wZfFaREEvc__nNSzERXGm6kJuo23YhZP8mVfGbnvPriAbhoCUgYQAvD_BwE#:~:text=If%20you%20do%20not%20send%20the%20original%20state%20back%20to%20the%20/continue%20endpoint%2C%20Auth0%20will%20lose%20the%20context%20of%20the%20login%20transaction%20and%20the%20user%20will%20not%20be%20able%20to%20log%20in%20due%20to%20an%20invalid_request%20error.)]

With that, could you please clarify what you intend to do with the dynamic query parameter? Would it be possible to append this information as a custom claim that you can decode later?

I look forward to your reply.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![userraj](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/userraj/32/42807_2.png) [@userraj](https://community.auth0.com/u/userraj)\
**Post date:** [February 23, 2023, 3:18am UTC](https://community.auth0.com/t/authorization-code-within-rules/100929/6 "2023-02-23T03:18:49Z")

</div>

Hello @rueben.tiow ,

The dynamic parameter is actually a value being passed from one site to another after the authentication process.  
And, yes, thank you for the mention, since my backup alternative was indeed the custom claim approach and I guess I will be going forward with it.

Thanks loads for the response.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 9, 2023, 3:19am UTC](https://community.auth0.com/t/authorization-code-within-rules/100929/7 "2023-03-09T03:19:20Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
