Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
)Functions ¶
Types ¶
type EncodedJwt ¶
type EncodedJwt string
func EncodeJwt ¶
func EncodeJwt(secret Secret, claims *jwt.StandardClaims) (EncodedJwt, error)
func GenJwt ¶
func GenJwt(secret Secret, fileId string) EncodedJwt
func GetJwt ¶
func GetJwt(r *http.Request) EncodedJwt
type Guard ¶
type Guard struct { SecretKey Secret // contains filtered or unexported fields }
Guard is to ensure data access security. There are 2 ways to check access:
- white list. It's checking request ip address.
- JSON Web Token(JWT) generated from secretKey. The jwt can come from:
- url parameter jwt=...
- request header "Authorization"
- cookie with the name "jwt"
The white list is checked first because it is easy. Then the JWT is checked.
The Guard will also check these claims if provided: 1. "exp" Expiration Time 2. "nbf" Not Before
Generating JWT:
- use HS256 to sign
- optionally set "exp", "nbf" fields, in Unix time, the number of seconds elapsed since January 1, 1970 UTC.
Referenced: https://github.com/pkieltyka/jwtauth/blob/master/jwtauth.go
Click to show internal directories.
Click to hide internal directories.