Documentation
¶
Index ¶
- Constants
- func GetExpiresAtFromRequest(r *http.Request) (time.Time, bool)
- func GetTokenStringFromRequest(r *http.Request) (string, errors.Error)
- func GetTokensFromCookie(r *http.Request) (string, string)
- func RemoveTokensFromCookie(w http.ResponseWriter)
- func SetTokensToCookie(w http.ResponseWriter, t *TokenDetails)
- func ValidateAccessToken(tokenString string, secretKey string) (string, string, errors.Error)
- func ValidateRefreshToken(tokenString string, refreshSecretKey string) (string, string, errors.Error)
- type TokenDetails
Constants ¶
const ( IOTechIssuer = "IOTech" Algorithm = "alg" Authorized = "authorized" ClaimAccessId = "access_id" ClaimRefreshId = "refresh_id" ClaimUsername = "user_name" ExpiresAt = "exp" Issuer = "iss" )
Constants related to JWT
const ( AccessTokenCookie = "IOTech_access_token" // This is not potential hardcoded credentials // nolint:gosec RefreshTokenCookie = "IOTech_refresh_token" )
Constants related to Cookie and HTTP headers
Variables ¶
This section is empty.
Functions ¶
func GetExpiresAtFromRequest ¶ added in v2.0.27
GetExpiresAtFromRequest returns the exp claim of the Bearer JWT in the Authorization header, or false if there is none. Cookies are not read, and the signature is NOT verified, so call this only after an authentication middleware.
func GetTokenStringFromRequest ¶
GetTokenStringFromRequest gets the token string from the request header
func GetTokensFromCookie ¶
GetTokensFromCookie gets the access token and refresh token from the request cookie
func RemoveTokensFromCookie ¶
func RemoveTokensFromCookie(w http.ResponseWriter)
RemoveTokensFromCookie removes the access token and refresh token from the response cookie
func SetTokensToCookie ¶
func SetTokensToCookie(w http.ResponseWriter, t *TokenDetails)
SetTokensToCookie sets the access token and refresh token to the response cookie
func ValidateAccessToken ¶
ValidateAccessToken validates the given access token string and gets the accessId and username.
Types ¶
type TokenDetails ¶
type TokenDetails struct {
AccessId string
AccessToken string
AtExpires int64
RefreshId string
RefreshToken string
RtExpires int64
}
func CreateToken ¶
func CreateToken(name, secretKey, refreshSecretKey string, atExpiresFromNow, reExpiresFromNow *int64) (*TokenDetails, errors.Error)
CreateToken creates a new token with the given name and expiration time, specified in hours from now with the default expiration time of 2 hours for access token and 7 days for refresh token