# SPA with Backend API - get email in JWT

**URL:** <https://community.auth0.com/t/spa-with-backend-api-get-email-in-jwt/38990>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [March 7, 2020, 8:24am UTC](https://community.auth0.com/t/spa-with-backend-api-get-email-in-jwt/38990 "2020-03-07T08:24:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luke1988](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/luke1988/32/13158_2.png) [@luke1988](https://community.auth0.com/u/luke1988)\
**Post date:** [March 7, 2020, 8:24am UTC](https://community.auth0.com/t/spa-with-backend-api-get-email-in-jwt/38990/1 "2020-03-07T08:24:44Z")

</div>

Hi guys,

I am trying to implement Auth0 into my Angular SPA with [ASP.NET](http://ASP.NET) Core API backend. I am failing on getting user email on serverside from JWT. It is simply not in claims. Only user identifier I receive is auth0|5e62d40ee7bxxxxxxxxxxxxxxxx.

I also followed couple of posts here like ‘use custom rule’ which did not help:

```
function (user, context, callback) {
  
  // context.accessToken.email = user.email;
  context.accessToken['xxxxx.email'] = user.email;
  // context.accessToken['my-account.eu.auth0.com.email'] = user.email;
	
  callback(null, user, context);
}

```

None of this helped. What I am doing wrong?  
Thanks!

---

<div class="post-metadata">

**Author:** ![mathiasconradt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mathiasconradt/32/12758_2.png) [@mathiasconradt](https://community.auth0.com/u/mathiasconradt)\
**Post date:** [March 7, 2020, 9:57am UTC](https://community.auth0.com/t/spa-with-backend-api-get-email-in-jwt/38990/2 "2020-03-07T09:57:54Z")

</div>

Hi @luke1988,

your namespacing is wrong, the namespace must be a proper url, such as:

`context.accessToken['http://my-namespace/email'] = user.email`

> Namespaces are arbitrary identifiers, so technically you can call your namespace anything you want. However, using the URI of a resource you control is conventional (following the way XML namespaces are defined).  
> ([Create Custom Claims](https://auth0.com/docs/tokens/guides/create-namespaced-custom-claims))

Just wondering, why do you need the email in the access token? Is that the reference your using on your backend to link a user, instead of the `sub` claim?

---

<div class="post-metadata">

**Author:** ![luke1988](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/luke1988/32/13158_2.png) [@luke1988](https://community.auth0.com/u/luke1988)\
**Post date:** [March 7, 2020, 10:31am UTC](https://community.auth0.com/t/spa-with-backend-api-get-email-in-jwt/38990/3 "2020-03-07T10:31:34Z")

</div>

Thank you for your time during weekend.

Why I need email: I am implementing Auth0 to existing app which has backend API built on top of user identity in form of email. Anything that API uses is queried using user email.

So, without an email I have to either rewrite whole API or add some sort of middleware which takes sub (Auth0 internal user ID) and lookup in dbo select email from dbo.users where auth0\_id = {{id from jwt}}

Both options are lets say… not ideal 🙂

Oh wait… namespace must be a valid URL but is somehow related with Audenice or settings in Auth0? Or it could be literally [http://my-namespace/email](http://my-namespace/email) ?

---

<div class="post-metadata">

**Author:** ![mathiasconradt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mathiasconradt/32/12758_2.png) [@mathiasconradt](https://community.auth0.com/u/mathiasconradt)\
**Post date:** [March 7, 2020, 10:38am UTC](https://community.auth0.com/t/spa-with-backend-api-get-email-in-jwt/38990/4 "2020-03-07T10:38:35Z")

</div>

> [@luke1988](#):
>
> Oh wait… namespace must be a valid URL but is somehow related with Audenice or settings in Auth0? Or it could be literally [http://my-namespace/email](http://my-namespace/email) ?

It can be anything, doesn’t have to match the audience, can even be literally the example URL I put above.

---

<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 22, 2020, 10:38am UTC](https://community.auth0.com/t/spa-with-backend-api-get-email-in-jwt/38990/5 "2020-03-22T10:38:35Z")

</div>

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