我使用了 golang jwt 中間件。
e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
SigningKey: []byte(os.Getenv("Signing_Key")),
TokenLookup: "header:x-auth-token",
}))
它等待所有功能的令牌,但我不想將此中間件用于登錄功能。如何防止這種情況?
uj5u.com熱心網友回復:
有一個skipper功能。您可以使用它來檢查要跳過的路線。
JWTConfig struct {
// Skipper defines a function to skip middleware.
Skipper Skipper
...
}
檢查一個例子:
e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
SigningKey: []byte(os.Getenv("Signing_Key")),
TokenLookup: "header:x-auth-token",
Skipper: func(c echo.Context) bool {
// Skip middleware if path is equal 'login'
if c.Request().URL.Path == "/login" {
return true
}
return false
},
}))
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/404478.html
標籤:
上一篇:使用GoAdminSDK使用IdToken在實時資料庫上進行身份驗證
下一篇:如何在Go中將多行編組為XML?
