# Code Verifier Storage and Retrieval

**URL:** <https://community.auth0.com/t/code-verifier-storage-and-retrieval/79793>\
**Category:** Get Help\
**Created:** [March 13, 2022, 7:08pm UTC](https://community.auth0.com/t/code-verifier-storage-and-retrieval/79793 "2022-03-13T19:08:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![milotis](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/milotis/32/33224_2.png) [@milotis](https://community.auth0.com/u/milotis)\
**Post date:** [March 13, 2022, 7:08pm UTC](https://community.auth0.com/t/code-verifier-storage-and-retrieval/79793/1 "2022-03-13T19:08:09Z")

</div>

For the Auth0 Authorization Code flow with PKCE, I have been using the domain `company.us.auth0.com/authorize...` to initiate the PKCE flow and I redirect to a callback on my server, `/oauth?code=...`, and can retrieve an access code from the query params. The [next step](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-proof-key-for-code-exchange-pkce) is to send the code and code\_verifier to /oauth/token, but I do not currently have a way to retrieve the code\_verifier.

Do I need to update the flow so that my native app sends the code\_verifier to my server for storage and have my server send the request the `/authorize`? And after my server gets an id token, access token, and refresh token, can the native desktop app use the code\_verifier to poll my server for the values?

Note there is not an Auth0 SDK available that I can use and I am trying to work around that.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [March 15, 2022, 11:23pm UTC](https://community.auth0.com/t/code-verifier-storage-and-retrieval/79793/3 "2022-03-15T23:23:17Z")

</div>

Hey there @milotis, good question!

Given there isn’t an Auth0 SDK for you use case, I’d be curious to know what sort of technology you are building this for - Do you mind sharing? Perhaps someone from the community speak from personal experience.

> [@milotis](#):
>
> Do I need to update the flow so that my native app sends the code\_verifier to my server for storage and have my server send the request the `/authorize` ? And after my server gets an id token, access token, and refresh token, can the native desktop app use the code\_verifier to poll my server for the values?

While the storage of the `code_verifier` is completely up to you, in the case of public clients (native + SPA) this is typically stored in memory and session/local storage respectively. Note that the `code_verifier` is used in unison with the `code` returned from the /authorize in exchange for tokens at the /token endpoint. Especially important here is that the `code` is only good for one use. Here’s a good step by step explanation of the PKCE flow:

> **[Authorization Code Flow with Proof Key for Code Exchange (PKCE)](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-proof-key-for-code-exchange-pkce#how-it-works)**
>
> Learn how the Authorization Code flow with Proof Key for Code Exchange (PKCE) works and why you should use it for native and mobile apps.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![milotis](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/milotis/32/33224_2.png) [@milotis](https://community.auth0.com/u/milotis)\
**Post date:** [March 16, 2022, 2:29am UTC](https://community.auth0.com/t/code-verifier-storage-and-retrieval/79793/4 "2022-03-16T02:29:26Z")

</div>

Thanks 🙂 I don’t understand the diagram because the [App] block appears to be doing stuff for the native application and the server from my apparent misunderstanding of how this flow works. I have a native app that generates a code verifier and code challenge and it opens the system browser to the /authorize endpoint. Also, the diagram from the Auth0 shows the Auth0 tenant sending the code directly to the App, but in my case that would go to the system browser or my server and I cannot retrieve values from the system browser from my native app. If the app in the diagram can send the Code Verifier and Code challenge and get an id token and access token, then I assume it must be safe for my native app to poll my server with those values to retrieve the access code, but I don’t see a way to map those values to the returned access code because it is the only value returned from the /authorize endpoint.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [March 18, 2022, 11:46pm UTC](https://community.auth0.com/t/code-verifier-storage-and-retrieval/79793/6 "2022-03-18T23:46:37Z")

</div>

Unfortunately, the OAuth/OIDC flow as it relates to native desktop applications does introduce some additional complexity as you’ve noticed. Primarily, native desktop apps don’t have the luxury of relying on browser features like Chrome Custom Tabs (Android) or Safari View Controller(iOS) to perform OAuth related requests. Traditionally, many apps have relied on embedded web views to carry out OAuth related requests, but this is not encouraged as outlined in this [video](https://auth0.com/docs/videos/learn-identity-series/desktop-and-mobile-apps) (discussed beginning around 10:18).

> [@milotis](#):
>
> Also, the diagram from the Auth0 shows the Auth0 tenant sending the code directly to the App, but in my case that would go to the system browser or my server and I cannot retrieve values from the system browser from my native app

I believe this is where the an [Inter-App URI](https://datatracker.ietf.org/doc/html/rfc8252#section-5) or [Private URI Scheme](https://tools.ietf.org/id/draft-ietf-oauth-native-apps-12.html#custom-uri-scheme) comes into play as referenced in both the linked specifications.

Hope this helps to clarify!

---

<div class="post-metadata">

**Author:** ![milotis](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/milotis/32/33224_2.png) [@milotis](https://community.auth0.com/u/milotis)\
**Post date:** [March 22, 2022, 2:02am UTC](https://community.auth0.com/t/code-verifier-storage-and-retrieval/79793/7 "2022-03-22T02:02:50Z")

</div>

Thanks, again. Sorry, I have overlooked somethings while attempting to do this, but I have come up with a possible solution and would appreciate any feedback.

First, my native application opens the system browser to a URL on my server which saves the values of state, code challenge, and code challenge method. You would have to be logged in on the system browser for this to work.

Then, my server sends the client a redirect to `company.us.auth0.com/authorize` with the same parameters, but it has a callback to my server so I can append the returned code yielding (state, code challenge, code challenge method, code).

Finally, either my server can request an (id token, access token, refresh token) and append it to (state, code challenge, code challenge method, code) and the client can poll the server for those values using (state, code challenge, code challenge method) OR I could first let the native application poll for the code and send another request to generate the other tokens, but that seems redudant.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [April 6, 2022, 2:03am UTC](https://community.auth0.com/t/code-verifier-storage-and-retrieval/79793/8 "2022-04-06T02:03:11Z")

</div>

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