# Using Go to check tokens, how can I get the email address?

**URL:** <https://community.auth0.com/t/using-go-to-check-tokens-how-can-i-get-the-email-address/115861>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [September 10, 2023, 6:37pm UTC](https://community.auth0.com/t/using-go-to-check-tokens-how-can-i-get-the-email-address/115861 "2023-09-10T18:37:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KLP](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/klp/32/49127_2.png) [@KLP](https://community.auth0.com/u/KLP)\
**Post date:** [September 10, 2023, 6:37pm UTC](https://community.auth0.com/t/using-go-to-check-tokens-how-can-i-get-the-email-address/115861/1 "2023-09-10T18:37:29Z")

</div>

I’m using react auth0 sdk, and I’m making a GET /users/me to my Go api.

I am wondering how I can get the email from the token. When I inspect my token on [jwt.io](http://jwt.io), I see

```auto
{
  "nickname": "xxxxx",
  "name": "xxxxxx@xxxxxx.com",
  "picture": "...........",
  "updated_at": "2023-09-10T18:05:46.705Z",
  "email": "xxxxx@xxxxx.com",
  "email_verified": false,
  "iss": "........",
  "aud": ".............",
  "iat": 1694370629,
  "exp": 1694372429,
  "sub": "auth0|............",
  "sid": ".........",
  "nonce": "........"
}

```

Here’s my Go code-

```auto
type CustomClaims struct {
	Scope string `json:"scope"`
}

// Validate does nothing for this example, but we need
// it to satisfy validator.CustomClaims interface.
func (c CustomClaims) Validate(ctx context.Context) error {
	return nil
}

// EnsureValidToken is a middleware that will check the validity of our JWT.
func (h *Http) EnsureValidToken(next http.Handler) http.Handler {

	middleware := jwtmiddleware.New(
		h.jwtValidator.ValidateToken,
		jwtmiddleware.WithErrorHandler(h.jwtErrorHandler),
	)

	return middleware.CheckJWT(next)
}

```

Unfortunately here’s the JSON of what I get when I check what is added to the context -

```auto
{
    "CustomClaims": {
        "email": "",
        "scope": "openid profile email"
    },
    "RegisteredClaims": {
        "iss": ".........",
        "sub": "auth0|...........",
        "aud": [
            "com.myapp.api",
            "......../userinfo"
        ],
        "exp": 1694372429,
        "iat": 1694370629
    }
}

```

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 12, 2023, 10:38pm UTC](https://community.auth0.com/t/using-go-to-check-tokens-how-can-i-get-the-email-address/115861/3 "2023-09-12T22:38:50Z")

</div>

Hey @KLP welcome to the community!

Thanks for the detailed description of what you’re seeing 🙂

> [@KLP](#):
>
> ```auto
> {
> "nickname": "xxxxx",
> "name": "xxxxxx@xxxxxx.com",
> "picture": "...........",
> "updated_at": "2023-09-10T18:05:46.705Z",
> "email": "xxxxx@xxxxx.com",
> "email_verified": false,
> "iss": "........",
> "aud": ".............",
> "iat": 1694370629,
> "exp": 1694372429,
> "sub": "auth0|............",
> "sid": ".........",
> "nonce": "........"
> }
> 
> ```

This is a decoded ID token whereas the token in your Go code is an access token - Are you adding `email` as a custom claim to the access token? If not, I believe that should do the trick. You’ll need to add it using a [post-login action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow), something like:

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (event.authorization) {
    api.accessToken.setCustomClaim('email', event.user.email);
  }
}

```

The email claim is not added to access tokens by default.

Keep us posted!

---

<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:** [December 22, 2023, 11:50pm UTC](https://community.auth0.com/t/using-go-to-check-tokens-how-can-i-get-the-email-address/115861/4 "2023-12-22T23:50:32Z")

</div>

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