1 回答

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊
SecureCookie 所做的唯一一件事就是將您的令牌值轉(zhuǎn)換為編碼字符串。然后,在將 cookie 設(shè)置為客戶端時(shí),您可以將其視為令牌的新值。
可以使用Encode任何數(shù)據(jù)類型,不一定必須是 a map[string]string,您可以直接將 jwt 令牌傳遞給它。
encoded, err := s.Encode("jwt-token", "value.of.jwt.token.here")
之后,不能比示例中的鍵值格式更簡(jiǎn)單:
cookie := &http.Cookie{
Name: "jwt-token", // <- should be any unique key you want
Value: encoded, // <- the token after encoded by SecureCookie
Path: "/",
Secure: true,
HttpOnly: true,
}
http.SetCookie(w, cookie)
當(dāng)您想再次驗(yàn)證令牌時(shí),請(qǐng)記住encoded使用正確的密鑰對(duì) cookie進(jìn)行解碼。jwt-token
- 1 回答
- 0 關(guān)注
- 115 瀏覽
添加回答
舉報(bào)