refactor: allow purpose to be none
This commit is contained in:
parent
749a932663
commit
d5118beb58
|
@ -26,6 +26,7 @@ var (
|
|||
const (
|
||||
JWTPurposeLogin JWTPurpose = "login"
|
||||
JWTPurpose2FA JWTPurpose = "2fa"
|
||||
JWTPurposeNone JWTPurpose = ""
|
||||
)
|
||||
|
||||
func JWTGenerateToken(domain string, privateKey ed25519.PrivateKey, userID uint, purpose JWTPurpose) (string, error) {
|
||||
|
|
|
@ -104,9 +104,6 @@ func AuthMiddleware(options AuthMiddlewareOptions) func(http.Handler) http.Handl
|
|||
if options.AuthContextKey == "" {
|
||||
options.AuthContextKey = DEFAULT_AUTH_CONTEXT_KEY
|
||||
}
|
||||
if options.Purpose == "" {
|
||||
panic("purpose is missing")
|
||||
}
|
||||
|
||||
domain := options.Config.Config().Core.Domain
|
||||
|
||||
|
@ -126,7 +123,7 @@ func AuthMiddleware(options AuthMiddlewareOptions) func(http.Handler) http.Handl
|
|||
claim, err := account.JWTVerifyToken(authToken, domain, options.Identity, func(claim *jwt.RegisteredClaims) error {
|
||||
aud, _ := claim.GetAudience()
|
||||
|
||||
if slices.Contains[jwt.ClaimStrings, string](aud, string(options.Purpose)) == false {
|
||||
if options.Purpose != account.JWTPurposeNone && slices.Contains[jwt.ClaimStrings, string](aud, string(options.Purpose)) == false {
|
||||
return account.ErrJWTInvalid
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue