File tree 1 file changed +10
-1
lines changed
1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,9 @@ type GinJWTMiddleware struct {
56
56
// User can define own Unauthorized func.
57
57
Unauthorized func (* gin.Context , int , string )
58
58
59
+ // Set the identity handler function
60
+ IdentityHandler func (jwt.MapClaims ) string
61
+
59
62
// TokenLookup is a string in the form of "<source>:<name>" that is used
60
63
// to extract token from the request.
61
64
// Optional. Default value "header:Authorization".
@@ -110,6 +113,12 @@ func (mw *GinJWTMiddleware) MiddlewareInit() error {
110
113
}
111
114
}
112
115
116
+ if mw .IdentityHandler == nil {
117
+ mw .IdentityHandler = func (claims jwt.MapClaims ) string {
118
+ return claims ["id" ].(string )
119
+ }
120
+ }
121
+
113
122
if mw .Realm == "" {
114
123
return errors .New ("realm is required" )
115
124
}
@@ -150,7 +159,7 @@ func (mw *GinJWTMiddleware) middlewareImpl(c *gin.Context) {
150
159
151
160
claims := token .Claims .(jwt.MapClaims )
152
161
153
- id := claims [ "id" ].( string )
162
+ id := mw . IdentityHandler ( claims )
154
163
c .Set ("JWT_PAYLOAD" , claims )
155
164
c .Set ("userID" , id )
156
165
You can’t perform that action at this time.
0 commit comments