# Best practice with a custom authentication flow

**URL:** <https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425>\
**Category:** Get Help\
**Created:** [September 8, 2020, 6:25pm UTC](https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425 "2020-09-08T18:25:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![yegor211](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yegor211/32/19979_2.png) [@yegor211](https://community.auth0.com/u/yegor211)\
**Post date:** [September 8, 2020, 6:25pm UTC](https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425/1 "2020-09-08T18:25:10Z")

</div>

Hi there!

I’m doing a research on the options available for the auth flow that I have in my mind and I have a little bit of a struggle to choose the correct way. Let me describe how and where it should work so you can give me your thoughts.

So let’s say I have the super simple backend which has an API secured by Auth0 middleware.

Now, I’ve got an app (let it be a browser extension but it could be anything) where I’d like to implement my own login page. Imagine I have a simple html page with 2 inputs for login/password and an action button (“Login”). I don’t want the user to be redirected to the Auth0 landing/login page. I want their login data be sent to the Auth0 authentication API and get access/refresh tokens in the response. I don’t understand what is the point of the callback URL in this case, since the best option would be to have the tokens being returned as a JSON response, and upon success I would manually use those tokens with my backend, store them and do whatever I want.

---

<div class="post-metadata">

**Author:** ![yegor211](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yegor211/32/19979_2.png) [@yegor211](https://community.auth0.com/u/yegor211)\
**Post date:** [September 9, 2020, 9:49am UTC](https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425/2 "2020-09-09T09:49:51Z")

</div>

I’ve also came across the problem, that I am unable to obtain the refresh token.

I’m using `/authorize` endpoint to get the code with `offline_access` scope, then I’m trying to request `/oauth/token` but only `access_token` is returned.

I’ve read that only with PKCE you can get refresh tokens, is that true? If yes, why only Native and Single-Page applications are mentioned for PKCE? I’ve got a simple Node.js backend server, which has got a couple of endpoints that are secured by Auth0. My Chrome extension authorizes the user and I want to obtain the `refresh_token` along with the `access_token` in order for users to be able to use my API without any extra interactions after they authorized or until they will log out.

What am I missing?

---

<div class="post-metadata">

**Author:** ![yegor211](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yegor211/32/19979_2.png) [@yegor211](https://community.auth0.com/u/yegor211)\
**Post date:** [September 9, 2020, 9:54am UTC](https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425/3 "2020-09-09T09:54:40Z")

</div>

Just tried implementing PKCE into my App and still only got `access_token` in response. Is this due to my app being a Regular Web App and not the Native/Single-Page? But what if I need refresh tokens for my app and it seems to be more of a regular web app, than one of those?

---

<div class="post-metadata">

**Author:** ![yegor211](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yegor211/32/19979_2.png) [@yegor211](https://community.auth0.com/u/yegor211)\
**Post date:** [September 9, 2020, 10:35am UTC](https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425/4 "2020-09-09T10:35:04Z")

</div>

The API documentation says:

> [@](#):
>
> The `refresh_token` will only be present in the response if you included the `offline_access` scope and enabled **Allow Offline Access** for your API in the Dashboard

I am including the “offline\_access” scope and I’ve enabled the “Allow OfflineAccess” for my API. No refresh\_token being returned from `oauth/token`.

---

<div class="post-metadata">

**Author:** ![yegor211](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yegor211/32/19979_2.png) [@yegor211](https://community.auth0.com/u/yegor211)\
**Post date:** [September 9, 2020, 10:41am UTC](https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425/5 "2020-09-09T10:41:39Z")

</div>

Ok, used the “Monitoring” tool and it clearly says the following:

> [@](#):
>
> The scope ‘offline\_access’ was requested, but no ‘refresh\_token’ was issued because the authorization code exchange originated from a browser

So how should I deal with the refresh tokens in my app, which turns out to be a Chrome extension with a simple Node.js backend?

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [September 9, 2020, 1:50pm UTC](https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425/6 "2020-09-09T13:50:56Z")

</div>

Hi @yegor211

The short answer is “don’t do what you are doing”.

There are YEARS of security experience in the design of the standard authentication flows. Don’t produce custom ones. You WILL open your app up with security holes.

With your architecture, you should use either the PKCE flow (treating your app as a SPA) or Auth Code (treating your app as a classic web app). For both approaches, you will use the Universal Login Page and NOT host the login page yourself.

John

---

<div class="post-metadata">

**Author:** ![yegor211](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yegor211/32/19979_2.png) [@yegor211](https://community.auth0.com/u/yegor211)\
**Post date:** [September 9, 2020, 10:10pm UTC](https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425/7 "2020-09-09T22:10:03Z")

</div>

Thanks for the answer!

So anyway, there is an option to use an embedded login, which is also a way to go right?

But let’s skip this for now. I will use a normal universal login page.

I am mostly concerned about access restriction to some of my backend endpoints in my app, which turns out to be a Chrome extension.

I’ve went through your docs a lot and my head is filled out with lots of information. I’d be glad to hear an answer from you to the following question: how should the authorization be done in my app, so that once the user logs in, he can use my app easily until he logs out of it, assuming the session is infinite? Since the Chrome extension is a browser application, the tokens must be stored locally. But that is not allowed, the refresh token is not returned from the `oauth/token` endpoint for the browser, so I cannot code the logic behind token rotation. How should the refresh token be obtained and stored in order for my app to be able to refresh the access token when I need?

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [September 10, 2020, 1:34pm UTC](https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425/8 "2020-09-10T13:34:43Z")

</div>

Hi @yegor211

Your app is considered to be a SPA, so will require the Auth Code + PKCE flow

For refresh tokens, see this blog post: [Securing Single Page Applications with Refresh Token Rotation](https://auth0.com/blog/securing-single-page-applications-with-refresh-token-rotation/)

John

---

<div class="post-metadata">

**Author:** ![yegor211](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yegor211/32/19979_2.png) [@yegor211](https://community.auth0.com/u/yegor211)\
**Post date:** [September 10, 2020, 3:48pm UTC](https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425/9 "2020-09-10T15:48:36Z")

</div>

Thank you, I will try that stuff out and will get back to you with result.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [September 11, 2020, 9:07am UTC](https://community.auth0.com/t/best-practice-with-a-custom-authentication-flow/49425/10 "2020-09-11T09:07:34Z")

</div>

Let us know if you have any other questions down the road!
