appleboy / appleboy/gin-jwt

different Authorizator depending on Router Groups

Open
#25 5 comments 11 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
3k
Forks
387
Avg merge
4h 16m
Merged PRs (30d)
1

Description

Hi,

(thx for having merged so quickly my PR on Context injection ^^)

I'm facing an issue, and I think it may be a functional / logical problem in Authorization implementation and / or limitations cause by lack of informations about groups in gin.Context.

For example, here are my groups definitions for admin/users :

``` go
admin := r.Group("/admin")
admin.Use(authMiddleware.MiddlewareFunc())
{
users := admin.Group("/users")
users.GET("/:username", user.ByUsernameHandler)
users.POST("", registration.RegisterHandler)
users.GET("", user.AllUsersHandler)
}
```

By using your Authorizator callback, I have to be aware of two informations :
- roles of user (stored in my DB)
- which route matches to the request and in which group(s) it belongs

Each leads me to an issue :
- User roles can be accessed only by querying for the second time (it has already been queried in Authenticator Handler). I've been trying to set user in context with c.Set("User", user) in Authenticator and access it in Authorizator, but unsuccessfully, c.Get return false for "exists" return param…
- gin.Context does not contain Group… Just handler name…

Should I implement my own solution like writing a specific Middleware, with an string argument telling me what group is called ? Or is there any more elegant way to fix this ?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing authMiddleware.MiddlewareFunc(), the Authenticator callback, and the Authorizator callback, then inspect how gin.Context carries values and identifies matched handlers. Reproduce the grouped-route case and verify whether user data and route-group information are available where authorization runs; done means the issue has a documented, working path for both without an unnecessary second user lookup.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
authorization, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.