# How can I use Auth0 to both authenticate on client and server?

**URL:** <https://community.auth0.com/t/how-can-i-use-auth0-to-both-authenticate-on-client-and-server/86625>\
**Category:** Get Help\
**Tags:** nginx, flutter\
**Created:** [July 7, 2022, 9:50pm UTC](https://community.auth0.com/t/how-can-i-use-auth0-to-both-authenticate-on-client-and-server/86625 "2022-07-07T21:50:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesnicholls04](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jamesnicholls04/32/34658_2.png) [@jamesnicholls04](https://community.auth0.com/u/jamesnicholls04)\
**Post date:** [July 7, 2022, 9:50pm UTC](https://community.auth0.com/t/how-can-i-use-auth0-to-both-authenticate-on-client-and-server/86625/1 "2022-07-07T21:50:49Z")

</div>

Hi everyone,

I am authenticating users on the client (Flutter app) via Auth0, then wish to gate access to my API server to those users only. I would like the users to authenticate only the first time they use the app, and never again - certainly not each time they make a request to my server.

I suppose my question really is this: could I pass some access token, that I could acquire on the client, (as the user will already be authenticated by Auth0), directly to NGINX - and thereby grant access to my server. That is, the user would not have to _reauthenticate_ with Auth0 when the request hits the server?

Thank you so much for your time, and apologies if I’m miles off base here - very new to this stuff and any help is thoroughly appreciated!

---

<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:** [July 8, 2022, 2:31pm UTC](https://community.auth0.com/t/how-can-i-use-auth0-to-both-authenticate-on-client-and-server/86625/2 "2022-07-08T14:31:29Z")

</div>

Hi @jamesnicholls04

You are on the right track. Your API should be defined as an API in Auth0, and your flutter app should request an access token for it. This access token will have a lifetime, and when it expires, you use silent authentication to get a new one (or refresh tokens).

> **[APIs](https://auth0.com/docs/get-started/apis)**
>
> Explore key topics related to working with APIs.

John

---

<div class="post-metadata">

**Author:** ![jamesnicholls04](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jamesnicholls04/32/34658_2.png) [@jamesnicholls04](https://community.auth0.com/u/jamesnicholls04)\
**Post date:** [July 11, 2022, 4:00pm UTC](https://community.auth0.com/t/how-can-i-use-auth0-to-both-authenticate-on-client-and-server/86625/3 "2022-07-11T16:00:23Z")

</div>

Hi John,

First off - thank you so much! I think I’ve finally got a plan of action, that I’d like to run past you quickly if you don’t mind:

My API server is a flask application, and I plan to follow this tutorial: [Auth0 Flask API Tutorial](https://auth0.com/docs/quickstart/backend/python/interactive)

My guess is that in implementing this SDK, and with my Flutter auth, I’ll be using this pattern: [Call Your API Using the Device Authorization Flow](https://auth0.com/docs/microsites/protect-api/protect-api)

My only slight qualm regards security. In particular:

Is it better practice to delegate authorisation to a reverse-proxy than authenticate on the server?

Perhaps I’m just being overly cautious but it would be great if you could reassure me that I’m doing the right thing!

Again, thank you so much for your time,

James

---

<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:** [July 12, 2022, 2:21pm UTC](https://community.auth0.com/t/how-can-i-use-auth0-to-both-authenticate-on-client-and-server/86625/4 "2022-07-12T14:21:09Z")

</div>

Hi @jamesnicholls04

Those pages you linked to explain the best way to do authz with APIs.

I’m not sure what you mean by reverse-proxy vs. server.

If you are talking about many different APIs all fronted by an API Gateway, it is very common to validate the access token at the gateway and not in the API itself.

There are tradeoffs on this. For a single API, with respect to the access token, a gateway doesn’t provide additional security and is an additional point of failure. However, the gateway may provide other security features that are desirable.

John

---

<div class="post-metadata">

**Author:** ![jamesnicholls04](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jamesnicholls04/32/34658_2.png) [@jamesnicholls04](https://community.auth0.com/u/jamesnicholls04)\
**Post date:** [July 12, 2022, 3:51pm UTC](https://community.auth0.com/t/how-can-i-use-auth0-to-both-authenticate-on-client-and-server/86625/5 "2022-07-12T15:51:49Z")

</div>

Hi John,

Apologies: by reverse-proxy I mean my NGINX web server and by server I mean my Flask application. What I really meant is an API Gateway!

My case is that of the single API, so it’s encouraging to hear that this approach seems best.

Thanks again,

James

---

<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:** [November 14, 2024, 9:52pm UTC](https://community.auth0.com/t/how-can-i-use-auth0-to-both-authenticate-on-client-and-server/86625/6 "2024-11-14T21:52:03Z")

</div>

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