|
1 | 1 | package jwt
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "crypto/rsa" |
5 |
| - "errors" |
6 |
| - "github.com/gogf/gf/g" |
7 |
| - "github.com/gogf/gf/g/net/ghttp" |
8 |
| - "io/ioutil" |
9 |
| - "net/http" |
10 |
| - "strings" |
11 |
| - "time" |
12 |
| - |
| 4 | + "crypto/rsa" |
| 5 | + "errors" |
13 | 6 | "github.com/dgrijalva/jwt-go"
|
| 7 | + "github.com/gogf/gf/frame/g" |
| 8 | + "github.com/gogf/gf/net/ghttp" |
| 9 | + "io/ioutil" |
| 10 | + "net/http" |
| 11 | + "strings" |
| 12 | + "time" |
14 | 13 | )
|
15 | 14 |
|
16 | 15 | // MapClaims type that uses the map[string]interface{} for JSON decoding
|
@@ -392,7 +391,7 @@ func (mw *GfJWTMiddleware) GetClaimsFromJWT(r *ghttp.Request) (MapClaims, error)
|
392 | 391 | }
|
393 | 392 |
|
394 | 393 | if mw.SendAuthorization {
|
395 |
| - token := r.GetParam("JWT_TOKEN").String() |
| 394 | + token := r.GetString("JWT_TOKEN") |
396 | 395 | if len(token) > 0 {
|
397 | 396 | r.Header.Set("Authorization", mw.TokenHeadName+" "+token)
|
398 | 397 | }
|
@@ -444,8 +443,8 @@ func (mw *GfJWTMiddleware) LoginHandler(r *ghttp.Request) {
|
444 | 443 |
|
445 | 444 | // set cookie
|
446 | 445 | if mw.SendCookie {
|
447 |
| - maxage := int(expire.Unix() - time.Now().Unix()) |
448 |
| - r.Cookie.SetCookie(mw.CookieName, tokenString, mw.CookieDomain, "/", maxage) |
| 446 | + maxage := int64(expire.Unix() - time.Now().Unix()) |
| 447 | + r.Cookie.SetCookie(mw.CookieName, tokenString, mw.CookieDomain, "/", time.Duration(maxage)*time.Millisecond) |
449 | 448 | }
|
450 | 449 |
|
451 | 450 | mw.LoginResponse(r, http.StatusOK, tokenString, expire)
|
@@ -501,8 +500,8 @@ func (mw *GfJWTMiddleware) RefreshToken(r *ghttp.Request) (string, time.Time, er
|
501 | 500 |
|
502 | 501 | // set cookie
|
503 | 502 | if mw.SendCookie {
|
504 |
| - maxage := int(expire.Unix() - time.Now().Unix()) |
505 |
| - r.Cookie.SetCookie(mw.CookieName, tokenString, mw.CookieDomain, "/", maxage) |
| 503 | + maxage := int64(expire.Unix() - time.Now().Unix()) |
| 504 | + r.Cookie.SetCookie(mw.CookieName, tokenString, mw.CookieDomain, "/", time.Duration(maxage)*time.Millisecond) |
506 | 505 | }
|
507 | 506 |
|
508 | 507 | return tokenString, expire, nil
|
@@ -656,13 +655,13 @@ func (mw *GfJWTMiddleware) unauthorized(r *ghttp.Request, code int, message stri
|
656 | 655 |
|
657 | 656 | // ExtractClaims help to extract the JWT claims
|
658 | 657 | func ExtractClaims(r *ghttp.Request) MapClaims {
|
659 |
| - claims := r.GetParam("JWT_PAYLOAD").Val() |
| 658 | + claims := r.GetParam("JWT_PAYLOAD") |
660 | 659 | return claims.(MapClaims)
|
661 | 660 | }
|
662 | 661 |
|
663 | 662 | // GetToken help to get the JWT token string
|
664 | 663 | func GetToken(r *ghttp.Request) string {
|
665 |
| - token := r.GetParam("JWT_TOKEN").String() |
| 664 | + token := r.GetString("JWT_TOKEN") |
666 | 665 | if len(token) == 0 {
|
667 | 666 | return ""
|
668 | 667 | }
|
|
0 commit comments