# How does a Backend API know which user made a request?

**URL:** <https://community.auth0.com/t/how-does-a-backend-api-know-which-user-made-a-request/8208>\
**Category:** Get Help\
**Tags:** jwt-validation, access-token\
**Created:** [September 16, 2017, 3:35am UTC](https://community.auth0.com/t/how-does-a-backend-api-know-which-user-made-a-request/8208 "2017-09-16T03:35:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lars.blumberg](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@lars.blumberg](https://community.auth0.com/u/lars.blumberg)\
**Post date:** [September 16, 2017, 3:35am UTC](https://community.auth0.com/t/how-does-a-backend-api-know-which-user-made-a-request/8208/1 "2017-09-16T03:35:43Z")

</div>

I’m having a single page web web application (SPA) that, using the implicit grant flow, gets an access token from auth0. That access token is used when making requests to my API.

How does my API know _which_ user has made a request? The access token, when decoded from JWT format to JSON, looks like this:

```
{
  'iss': 'https://MY-DOMAIN.eu.auth0.com/',
  'sub': 'auth0|59bbed...',
  'aud': 'localhost', 'https://MY-DOMAIN.eu.auth0.com/userinfo'],
  'azp': '...',
  'exp': 1505515504,
  'iat': 1505508304,
  'scope': 'openid profile'}
```

Is it sufficient to refer to the subject ` 'sub': 'auth0|59bbed...'` as the user who made the request?

Or should the backend instead get the user profile via `https://MY-DOMAIN.eu.auth0.com/userinfo`?

---

<div class="post-metadata">

**Author:** ![lars.blumberg](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@lars.blumberg](https://community.auth0.com/u/lars.blumberg)\
**Post date:** [September 17, 2017, 6:03pm UTC](https://community.auth0.com/t/how-does-a-backend-api-know-which-user-made-a-request/8208/2 "2017-09-17T18:03:09Z")

</div>

Answer to myself: `sub` identifies the subject (user) of the access token. So this data is sufficient to identify the user on whose behalf the request is made.

---

<div class="post-metadata">

**Author:** ![nurlan.nurmanov](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@nurlan.nurmanov](https://community.auth0.com/u/nurlan.nurmanov)\
**Post date:** [September 18, 2017, 12:47am UTC](https://community.auth0.com/t/how-does-a-backend-api-know-which-user-made-a-request/8208/3 "2017-09-18T00:47:16Z")

</div>

I have similar question and I would like to know are you sending the JWT to your backend? And your backend is validating the JWT which come from auth0 to either allow the user or not? I thought to secure the backend API, the backend API itself needs to generate JWTs, but in your case it is not.

---

<div class="post-metadata">

**Author:** ![lars.blumberg](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@lars.blumberg](https://community.auth0.com/u/lars.blumberg)\
**Post date:** [September 18, 2017, 10:50pm UTC](https://community.auth0.com/t/how-does-a-backend-api-know-which-user-made-a-request/8208/4 "2017-09-18T22:50:28Z")

</div>

@nurlan.nurmanov The web frontend is sending the JWT access token to the backend. The backend then validates the token that was generated by auth0 and handed over to the web frontend at the end of the implicit grant flow. This is how the backend is secured and how requests from the frontend are authenticated at the backend. There’s no need for the backend to create tokens. The backend only validates the token using the public key that is created for the backend by auth0.

---

<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:** [March 2, 2018, 5:56am UTC](https://community.auth0.com/t/how-does-a-backend-api-know-which-user-made-a-request/8208/5 "2018-03-02T05:56:31Z")

</div>


