update go-chi and chi/jwtauth to v5
This commit is contained in:
parent
72fd12d0c4
commit
f7b222b7f3
13 changed files with 646 additions and 102 deletions
|
|
@ -3,7 +3,7 @@ package jwt
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/lestrrat-go/jwx/jwt"
|
||||
)
|
||||
|
||||
// AppClaims represent the claims parsed from JWT access token.
|
||||
|
|
@ -11,18 +11,17 @@ type AppClaims struct {
|
|||
ID int `json:"id,omitempty"`
|
||||
Sub string `json:"sub,omitempty"`
|
||||
Roles []string `json:"roles,omitempty"`
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
// ParseClaims parses JWT claims into AppClaims.
|
||||
func (c *AppClaims) ParseClaims(claims jwt.MapClaims) error {
|
||||
func (c *AppClaims) ParseClaims(claims map[string]interface{}) error {
|
||||
id, ok := claims["id"]
|
||||
if !ok {
|
||||
return errors.New("could not parse claim id")
|
||||
}
|
||||
c.ID = int(id.(float64))
|
||||
|
||||
sub, ok := claims["sub"]
|
||||
sub, ok := claims[jwt.SubjectKey]
|
||||
if !ok {
|
||||
return errors.New("could not parse claim sub")
|
||||
}
|
||||
|
|
@ -48,11 +47,10 @@ func (c *AppClaims) ParseClaims(claims jwt.MapClaims) error {
|
|||
type RefreshClaims struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
Token string `json:"token,omitempty"`
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
// ParseClaims parses the JWT claims into RefreshClaims.
|
||||
func (c *RefreshClaims) ParseClaims(claims jwt.MapClaims) error {
|
||||
func (c *RefreshClaims) ParseClaims(claims map[string]interface{}) error {
|
||||
token, ok := claims["token"]
|
||||
if !ok {
|
||||
return errors.New("could not parse claim token")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue