# Decoding Claims in Go

**URL:** <https://community.auth0.com/t/decoding-claims-in-go/149904>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [October 15, 2024, 1:37pm UTC](https://community.auth0.com/t/decoding-claims-in-go/149904 "2024-10-15T13:37:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kb\_dropfeed](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kb_dropfeed/32/61467_2.png) [@kb\_dropfeed](https://community.auth0.com/u/kb_dropfeed)\
**Post date:** [October 15, 2024, 1:37pm UTC](https://community.auth0.com/t/decoding-claims-in-go/149904/1 "2024-10-15T13:37:41Z")

</div>

Not sure, what I missed in the various hints?

I have an action:

 ![grafik](https://global.discourse-cdn.com/auth0/original/3X/a/b/ab89711ebdb2b6e0728588d74db67e3a349e8f83.jpeg)

It is triggered:

 ![grafik](https://global.discourse-cdn.com/auth0/original/3X/5/b/5bd17eb7c576faedb9d16a30423473231e97a3c3.png)

In the Action Details it is logged:

 ![grafik](https://global.discourse-cdn.com/auth0/original/3X/3/c/3cda22909b5e7a6e670b2fb7066bdf9f853b35b6.png)

But there are no Claims when I decode the token in go?

```auto
func (app *application) CallbackHandler(w http.ResponseWriter, r *http.Request) {
	// Retrieve the authorization code from the URL
	code := r.URL.Query().Get("code")
	if code == "" {
		http.Error(w, "Authorization code not found", http.StatusBadRequest)
		return
	}

	// Exchange the authorization code for an OAuth2 token
	token, err := app.authenticator.Exchange(context.Background(), code)
	if err != nil {
		http.Error(w, "Failed to exchange authorization code for token", http.StatusUnauthorized)
		return
	}

	// Verify the ID token to ensure its validity
	idToken, err := app.authenticator.VerifyIDToken(context.Background(), token)
	if err != nil {
		http.Error(w, "Failed to verify ID token", http.StatusInternalServerError)
		return
	}

	// Extract all claims from the ID token, including custom claims
	var claims map[string]interface{}
	if err := idToken.Claims(&claims); err != nil {
		http.Error(w, "Failed to parse token claims: "+err.Error(), http.StatusInternalServerError)
		return
	}

	// Marshal the claims to JSON for debugging purposes
	claimsJSON, err := json.MarshalIndent(claims, "", " ")
	if err != nil {
		http.Error(w, "Error marshaling claims to JSON", http.StatusInternalServerError)
		return
	}

	// Log all claims, including custom claims
	log.Printf("All claims: %s\n", string(claimsJSON))

	// For debug purposes, you can also print specific custom claims if needed
	// For example, if you have a custom claim like "https://example.com/roles"
	if roles, ok := claims["https://example.com/roles"].([]interface{}); ok {
		log.Printf("Custom roles claim: %v\n", roles)
	}

	// URL-encode the JSON string before storing it in the cookie
	encodedClaims := url.QueryEscape(string(claimsJSON))

	// Set the profile as a URL-encoded JSON string in a cookie
	http.SetCookie(w, &http.Cookie{
		Name: "profile",
		Value: encodedClaims,
		Path: "/",
	})

	// Set the access token in a cookie (not URL-encoded, assuming no special chars)
	http.SetCookie(w, &http.Cookie{
		Name: "access_token",
		Value: token.AccessToken,
		Path: "/",
	})

	// Redirect the user to the /user page
	http.Redirect(w, r, "/user", http.StatusSeeOther)
}

```

---

<div class="post-metadata">

**Author:** ![kb\_dropfeed](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kb_dropfeed/32/61467_2.png) [@kb\_dropfeed](https://community.auth0.com/u/kb_dropfeed)\
**Post date:** [October 15, 2024, 1:51pm UTC](https://community.auth0.com/t/decoding-claims-in-go/149904/3 "2024-10-15T13:51:31Z")

</div>

This is my debugging output:

```auto
2024/10/15 15:47:13 All token claims: map[aud:TDYhP3biGOpoIOPzmpcZJecfiILUPxWb exp:1.729036033e+09 iat:1.729000033e+09 iss:https://dropfeed.eu.auth0.com/ name:kb@v01.io nickname:kb picture:https://s.gravatar.com/avatar/bfe95aac9fc1da8664b2c8780927e381?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fkb.png sid:5CVgEjd67DXlXvNHfSLCeN1uF2C3zR4t sub:auth0|6708260ee90e2ada4ea5f232 updated_at:2024-10-15T13:47:12.126Z]
time=2024-10-15T15:47:13.324+02:00 level=INFO msg="ID Token claims:" !BADKEY="map[aud:TDYhP3biGOpoIOPzmpcZJecfiILUPxWb exp:1.729036033e+09 iat:1.729000033e+09 iss:https://dropfeed.eu.auth0.com/ name:kb@v01.io nickname:kb picture:https://s.gravatar.com/avatar/bfe95aac9fc1da8664b2c8780927e381?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fkb.png sid:5CVgEjd67DXlXvNHfSLCeN1uF2C3zR4t sub:auth0|6708260ee90e2ada4ea5f232 updated_at:2024-10-15T13:47:12.126Z]"

```

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [October 15, 2024, 2:00pm UTC](https://community.auth0.com/t/decoding-claims-in-go/149904/4 "2024-10-15T14:00:50Z")

</div>

Hi @kb_dropfeed

Welcome to the Auth0 Community!

Can you check if you can see the JWT claims → [https://jwt.io/](https://jwt.io/)

Thanks  
Dawid

---

<div class="post-metadata">

**Author:** ![kb\_dropfeed](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kb_dropfeed/32/61467_2.png) [@kb\_dropfeed](https://community.auth0.com/u/kb_dropfeed)\
**Post date:** [October 15, 2024, 3:48pm UTC](https://community.auth0.com/t/decoding-claims-in-go/149904/5 "2024-10-15T15:48:36Z")

</div>

> [@dawid.matuszczyk](#):
>
> Can you check if you can see the JWT claims → [https://jwt.io/](https://jwt.io/?_gl=1*371t23*_gcl_au*MjA5ODYxMjU3OS4xNzI4NTg2Nzc0*_ga*ODQxMTUyNzM3LjE3Mjg1ODY3NzU.*_ga_QKMSDV5369*MTcyOTAwNzA1Ni40LjEuMTcyOTAwNzA3Mi40NC4wLjA.)

Good Idea to debug this!

Sadly: no, it is not.

```auto
{
  "nickname": "kb",
  "name": "kb@v01.io",
  "picture": "https://s.gravatar.com/avatar/bfe95aac9fc1da8664b2c8780927e381?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fkb.png",
  "updated_at": "2024-10-15T15:47:03.079Z",
  "iss": "https://dropfeed.eu.auth0.com/",
  "aud": "TDYhP3biGOpoIOPzmpcZJecfiILUPxWb",
  "iat": 1729007223,
  "exp": 1729043223,
  "sub": "auth0|6708260ee90e2ada4ea5f232",
  "sid": "Ioisqk7m598R_V8ZTuOD8UuJSqKtGc1H"
}

```

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [October 16, 2024, 9:59am UTC](https://community.auth0.com/t/decoding-claims-in-go/149904/6 "2024-10-16T09:59:40Z")

</div>

Hi @kb_dropfeed

The clue of an issue can be that you are checking the Id\_token but adding custom claims to the access token.

Add this line above the line 10

`api.idToken.setCustomClaim('custom_email_claim', event.user.email)`

You should see claims for both the ID and access token right now.

[ID Token vs Access Token](https://auth0.com/blog/id-token-access-token-what-is-the-difference/)

Thanks  
Dawid

---

<div class="post-metadata">

**Author:** ![kb\_dropfeed](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kb_dropfeed/32/61467_2.png) [@kb\_dropfeed](https://community.auth0.com/u/kb_dropfeed)\
**Post date:** [October 16, 2024, 11:42am UTC](https://community.auth0.com/t/decoding-claims-in-go/149904/7 "2024-10-16T11:42:48Z")

</div>

Got it. I was adding the claims to the access token, but I was using the idtoken in my code.

I fixed it by adding the claims to the idtoken!

Thank you very much!

---

<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:** [October 30, 2024, 11:43am UTC](https://community.auth0.com/t/decoding-claims-in-go/149904/8 "2024-10-30T11:43:47Z")

</div>

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