# Custom Claims Go Gin

**URL:** <https://community.auth0.com/t/custom-claims-go-gin/122298>\
**Category:** Get Help\
**Tags:** sdks-quickstarts, quickstarts-other\
**Created:** [December 4, 2023, 6:12pm UTC](https://community.auth0.com/t/custom-claims-go-gin/122298 "2023-12-04T18:12:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheRabber](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/therabber/32/49698_2.png) [@TheRabber](https://community.auth0.com/u/TheRabber)\
**Post date:** [December 4, 2023, 6:12pm UTC](https://community.auth0.com/t/custom-claims-go-gin/122298/1 "2023-12-04T18:12:06Z")

</div>

Hey together,  
I’m currently learning go with gin and try to setup auth0 for authentication and authorization, the first part is working fine so far.  
Now I try to implement authorization based on rules using this tutorial:  
[https://auth0.com/docs/quickstart/backend/golang/01-authorization](https://auth0.com/docs/quickstart/backend/golang/01-authorization)

So far so good, as I’m using Gin I wanted to put the HasScope to its own middleware to call it in addition.

```auto
// HasScope checks whether our claims have a specific scope.
func (c CustomClaims) HasScope(expectedScope string) gin.HandlerFunc {
	return func(context *gin.Context) {
		result := strings.Split(c.Scope, " ")
		for i := range result {
			if result[i] == expectedScope {
				context.Next()
			}
		}

		context.AbortWithStatus(403)
	}
}

```

this is what I came up with so far, trying to extract it.  
Problem is that I probably shouldn’t be attaching that function to a CustomClaim, as I would need one for calling it afterwards, right?  
But somehow I’m stuck and can’t get further at the moment, does anyone have an idea on how to proceed with it?

---

<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:** [December 4, 2023, 10:00pm UTC](https://community.auth0.com/t/custom-claims-go-gin/122298/2 "2023-12-04T22:00:00Z")

</div>

Hey there @TheRabber welcome to the community!

> [@TheRabber](#):
>
> this is what I came up with so far, trying to extract it.

I unfortunately don’t have any experience with Gin 😕 Assuming you’re passing an [audience](https://community.auth0.com/t/what-is-the-audience/71414) in the original authorize request, you shouldn’t need to extract anything. The middleware should just be used to check for specific claims once you’ve successfully validated the access token.

---

<div class="post-metadata">

**Author:** ![TheRabber](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/therabber/32/49698_2.png) [@TheRabber](https://community.auth0.com/u/TheRabber)\
**Post date:** [December 4, 2023, 10:11pm UTC](https://community.auth0.com/t/custom-claims-go-gin/122298/4 "2023-12-04T22:11:52Z")

</div>

Hey tyf,  
thanks for the request, I think I found the solution, I was just to stupid to understand the code and how it should be used correctly I guess, I will validate that and put my findings here later as well.  
It’s more or less about the permissions you can set when configuring the api

---

<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:** [December 4, 2023, 10:18pm UTC](https://community.auth0.com/t/custom-claims-go-gin/122298/5 "2023-12-04T22:18:34Z")

</div>

Glad you found a solution 🙂 Please do share your findings!

---

<div class="post-metadata">

**Author:** ![TheRabber](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/therabber/32/49698_2.png) [@TheRabber](https://community.auth0.com/u/TheRabber)\
**Post date:** [December 5, 2023, 8:21pm UTC](https://community.auth0.com/t/custom-claims-go-gin/122298/7 "2023-12-05T20:21:58Z")

</div>

Problem was that I needed to add the permissions to custom claims:

```auto
type CustomClaims struct {
	Scope string `json:"scope"`
	Permissions []string `json:"permissions"`
}

```

---

<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:** [December 5, 2023, 8:35pm UTC](https://community.auth0.com/t/custom-claims-go-gin/122298/8 "2023-12-05T20:35:48Z")

</div>

Glad you were able to get this sorted, thanks for following up with your solution 🙂

---

<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 19, 2023, 8:36pm UTC](https://community.auth0.com/t/custom-claims-go-gin/122298/9 "2023-12-19T20:36:03Z")

</div>

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