# Public access tokens for a REST API

**URL:** <https://community.auth0.com/t/public-access-tokens-for-a-rest-api/49427>\
**Category:** Get Help\
**Created:** [September 8, 2020, 6:28pm UTC](https://community.auth0.com/t/public-access-tokens-for-a-rest-api/49427 "2020-09-08T18:28:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahsath](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ahsath/32/24096_2.png) [@ahsath](https://community.auth0.com/u/ahsath)\
**Post date:** [September 8, 2020, 6:28pm UTC](https://community.auth0.com/t/public-access-tokens-for-a-rest-api/49427/1 "2020-09-08T18:28:20Z")

</div>

Hey folks,

I built an express REST API and now wanted to integrate Auth0 the problem is that after reading countless articles and tutorials in the docs I couldn’t find an answer for my use case.

My thinking process goes as follows:

Have an API

Have a front end for users to register and where I after they pay generate them an API key or access token that is public and restricted to only reading from a certain domain (theirs) and that’s pretty much it

I’ve looked into M2M and SPA - API that are the most akin to my use case but I need to generate public tokens with certain restrictions

Thanks folks

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 9, 2020, 9:42pm UTC](https://community.auth0.com/t/public-access-tokens-for-a-rest-api/49427/3 "2020-09-09T21:42:59Z")

</div>

Hi @ahsath,

Welcome to the Community!

I think we need some clarification on this one. Do you mean your users are developers who are going to use your API? Or are you talking about how to secure some endpoints when a certain paying user is using your application?

---

<div class="post-metadata">

**Author:** ![ahsath](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ahsath/32/24096_2.png) [@ahsath](https://community.auth0.com/u/ahsath)\
**Post date:** [September 9, 2020, 10:09pm UTC](https://community.auth0.com/t/public-access-tokens-for-a-rest-api/49427/4 "2020-09-09T22:09:01Z")

</div>

Hi @dan.woda thank you for replying,

Yes, my users are developers who are going to use the API and since this is a must they’ll be doing cross-site requests. I’m looking a way to generate them an api key that’s is public so they can make authenticated requests against the API and I can monitor their quota limits, requests and so on.

I initially though on using SPA - API but that infers that the only one using the api are the users using my SPA and that’s not the case.

My thought was using the login widget, write a rule to given them `read:fares` permission and use the access token for calling the API but this access token is not public.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 10, 2020, 8:06pm UTC](https://community.auth0.com/t/public-access-tokens-for-a-rest-api/49427/5 "2020-09-10T20:06:20Z")

</div>

@ahsath,

We don’t have a buit-in method for creating _API keys_ so that a third party (like a customer/user of yours) can consume your custom API. There has been discussion on it in the forum, but it isn’t something I have seen implemented, or at least not a process that is well documented here or in our documentation.

The way I _have_ seen this use case covered is by creating an application for each user and making the client id and client secret available, which would let them request an access token for their app via the client credentials grant. This takes the ‘user’ out of it and is more of the OAuth way of doing things. You can create and delete applications (client id/secrets) programmatically using the Management API. [**Beware of the entity limits for each subscription type.**](https://auth0.com/docs/policies/entity-limit-policy)

One of the issues with handing out access tokens is this: they are not long-lived. Particularly tokens destined for SPAs. Usually, they expire after ~24hrs. They are meant to be refreshed on a regular basis, keeping the info in them up to date and making them less useful to an attacker who gets ahold of one, due to their short-lived nature.

---

<div class="post-metadata">

**Author:** ![ahsath](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ahsath/32/24096_2.png) [@ahsath](https://community.auth0.com/u/ahsath)\
**Post date:** [September 10, 2020, 8:16pm UTC](https://community.auth0.com/t/public-access-tokens-for-a-rest-api/49427/6 "2020-09-10T20:16:37Z")

</div>

Yeah I see, well thanks anyways

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 25, 2020, 8:16pm UTC](https://community.auth0.com/t/public-access-tokens-for-a-rest-api/49427/7 "2020-09-25T20:16:38Z")

</div>

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