Update go-chi/jwtauth to v3.3 and remove dgrijalva from direct dependencies
This commit is contained in:
parent
83b738e298
commit
a2d51bbfd8
7 changed files with 27 additions and 28 deletions
|
|
@ -2,8 +2,7 @@ package jwt
|
|||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/go-chi/jwtauth"
|
||||
)
|
||||
|
||||
// AppClaims represent the claims parsed from JWT access token.
|
||||
|
|
@ -14,7 +13,7 @@ type AppClaims struct {
|
|||
}
|
||||
|
||||
// ParseClaims parses JWT claims into AppClaims.
|
||||
func (c *AppClaims) ParseClaims(claims jwt.MapClaims) error {
|
||||
func (c *AppClaims) ParseClaims(claims jwtauth.Claims) error {
|
||||
id, ok := claims["id"]
|
||||
if !ok {
|
||||
return errors.New("could not parse claim id")
|
||||
|
|
@ -49,7 +48,7 @@ type RefreshClaims struct {
|
|||
}
|
||||
|
||||
// ParseClaims parses the JWT claims into RefreshClaims.
|
||||
func (c *RefreshClaims) ParseClaims(claims jwt.MapClaims) error {
|
||||
func (c *RefreshClaims) ParseClaims(claims jwtauth.Claims) error {
|
||||
token, ok := claims["token"]
|
||||
if !ok {
|
||||
return errors.New("could not parse claim token")
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package jwt
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/go-chi/jwtauth"
|
||||
"github.com/go-pg/pg/orm"
|
||||
)
|
||||
|
||||
|
|
@ -37,8 +37,8 @@ func (t *Token) BeforeUpdate(db orm.DB) error {
|
|||
}
|
||||
|
||||
// Claims returns the token claims to be signed
|
||||
func (t *Token) Claims() jwt.MapClaims {
|
||||
return jwt.MapClaims{
|
||||
func (t *Token) Claims() jwtauth.Claims {
|
||||
return jwtauth.Claims{
|
||||
"id": t.ID,
|
||||
"token": t.Token,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
jwt "github.com/dgrijalva/jwt-go"
|
||||
"github.com/go-chi/jwtauth"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -39,7 +38,7 @@ func (a *TokenAuth) Verifier() func(http.Handler) http.Handler {
|
|||
}
|
||||
|
||||
// GenTokenPair returns both an access token and a refresh token.
|
||||
func (a *TokenAuth) GenTokenPair(ca jwt.MapClaims, cr jwt.MapClaims) (string, string, error) {
|
||||
func (a *TokenAuth) GenTokenPair(ca jwtauth.Claims, cr jwtauth.Claims) (string, string, error) {
|
||||
access, err := a.CreateJWT(ca)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
|
|
@ -52,17 +51,17 @@ func (a *TokenAuth) GenTokenPair(ca jwt.MapClaims, cr jwt.MapClaims) (string, st
|
|||
}
|
||||
|
||||
// CreateJWT returns an access token for provided account claims.
|
||||
func (a *TokenAuth) CreateJWT(c jwt.MapClaims) (string, error) {
|
||||
jwtauth.SetIssuedNow(c)
|
||||
jwtauth.SetExpiryIn(c, a.JwtExpiry)
|
||||
func (a *TokenAuth) CreateJWT(c jwtauth.Claims) (string, error) {
|
||||
c.SetIssuedNow()
|
||||
c.SetExpiryIn(a.JwtExpiry)
|
||||
_, tokenString, err := a.JwtAuth.Encode(c)
|
||||
return tokenString, err
|
||||
}
|
||||
|
||||
// CreateRefreshJWT returns a refresh token for provided token Claims.
|
||||
func (a *TokenAuth) CreateRefreshJWT(c jwt.MapClaims) (string, error) {
|
||||
jwtauth.SetIssuedNow(c)
|
||||
jwtauth.SetExpiryIn(c, a.JwtRefreshExpiry)
|
||||
func (a *TokenAuth) CreateRefreshJWT(c jwtauth.Claims) (string, error) {
|
||||
c.SetIssuedNow()
|
||||
c.SetExpiryIn(a.JwtRefreshExpiry)
|
||||
_, tokenString, err := a.JwtAuth.Encode(c)
|
||||
return tokenString, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue