# Passing custom parameters through Auth0 login using state , is this recommended?

**URL:** <https://community.auth0.com/t/passing-custom-parameters-through-auth0-login-using-state-is-this-recommended/195064>\
**Category:** Get Help\
**Tags:** application, sso\
**Created:** [December 1, 2025, 11:12am UTC](https://community.auth0.com/t/passing-custom-parameters-through-auth0-login-using-state-is-this-recommended/195064 "2025-12-01T11:12:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![azamp3139](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/azamp3139/32/58800_2.png) [@azamp3139](https://community.auth0.com/u/azamp3139)\
**Post date:** [December 1, 2025, 11:12am UTC](https://community.auth0.com/t/passing-custom-parameters-through-auth0-login-using-state-is-this-recommended/195064/1 "2025-12-01T11:12:52Z")

</div>

I’m using Auth0 with Google social login and need to carry a custom parameter (like `countryCode`) from my app into the login flow and back to my redirect URL — even when the user cancels or gets an `access_denied` error.

`webAuth.authorize({`  
`connection: “google-oauth2”,`  
`state: JSON.stringify({ countryCode: “US” })`  
`});`

My questions:

1. Is using `state` to pass custom JSON data the recommended approach?

2. Will Auth0 always return the same `state` value unchanged, including in error flows?

3. Is there any issue with sending stringified or Base64-encoded JSON in `state`?

4. Is there a better/official way to persist custom parameters through the entire OAuth flow?

Just looking for clarity before fully adopting this pattern.

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [December 1, 2025, 2:02pm UTC](https://community.auth0.com/t/passing-custom-parameters-through-auth0-login-using-state-is-this-recommended/195064/3 "2025-12-01T14:02:56Z")

</div>

Hi @azamp3139,

Welcome back to the Auth0 Community!

I understand that you are looking for details for your specific questions around passing custom parameters through Auth0.

## Recommended solution for each point brought up

**1. Is using `state` to pass custom JSON data the recommended approach?**

**Yes.** For carrying **small, non-sensitive, contextual data** through the Authorization Code flow and back to your application, the [`state` parameter](https://auth0.com/docs/secure/attack-protection/state-parameters) is the best practice. Auth0 SDKs often provide an `appState` option that is internally encoded into the `state` parameter for this exact purpose.

**2. Will Auth0 always return the same `state` value unchanged, including in error flows?**

**Yes, the exact value is returned in all cases.** The OAuth/OIDC specification strictly requires the Authorization Server (Auth0) to return the `state` parameter in the response, whether it’s a success response (containing a `code`) or an error response (containing an `error` and `error_description`). This allows your application to correlate the response with the original request and maintain context.

**3. Is there any issue with sending stringified or Base64-encoded JSON in `state`?**

**No, this is common, but be mindful of the URL length limit.**

- **Stringified JSON** is fine, as long as your application URL-encodes it before sending it in the query string (which your SDK should handle).
- **Base64 encoding** is also a robust option.
- The primary concern is the **maximum length of a URL** , which is often around **2,048 characters** across browsers. Keep your custom data small and essential to avoid the “414 Request-URI Too Large” error.

**4. Is there a more official way to persist custom parameters throughout the entire OAuth flow?**

This is the recommended approach for your current use-case, with the following mentions:

- For small contextual data needed **before and after** the redirect, `state` is the official mechanism.
- **Alternative for extensive data:** If your data payload is large or sensitive, the recommended pattern is to store the data in your **server-side session or a temporary database record** and use the **`state` parameter as a unique key (or reference ID)** to look up that stored data upon the callback. This keeps the URL short and prevents sensitive data from being logged in browser history or server logs.

If you have any further questions, please don’t hesitate to reach out.

Have a good one,  
Vlad

---

<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:** [December 15, 2025, 2:03pm UTC](https://community.auth0.com/t/passing-custom-parameters-through-auth0-login-using-state-is-this-recommended/195064/4 "2025-12-15T14:03:09Z")

</div>

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