Documentation
¶
Index ¶
Constants ¶
const (
DefaultAlgorithm = "RS256"
)
Some default values
Variables ¶
This section is empty.
Functions ¶
func IsExpiredJWTError ¶
IsExpiredJWTError checks if err is JWT ValidationErrorExpired
func SaveUserClaims ¶
func SaveUserClaims(ctx context.Context, claims *UserClaims) context.Context
SaveUserClaims saves authorized user claims to the context
Types ¶
type Jwt ¶
type Jwt struct { PrivateKey *rsa.PrivateKey PublicKey *rsa.PublicKey }
Jwt is to sign and verify JWT
func NewJWTFromPrivatePem ¶
NewJWTFromPrivatePem creates signer and verifier from PEM string
func NewJWTFromPublicPem ¶
NewJWTFromPublicPem initializes jwt verifier from public string An error will be returned if returned object is used to sign a JWT
func NewRandomJwt ¶
NewRandomJwt generates random RSA keys for RSA algorithm This is to simplify setup jwt verify for unit test
type Signer ¶
type Signer interface {
Sign(ctx context.Context, claims *UserClaims) (string, error)
}
Signer defines an interface to sign authentication token
type UserClaims ¶
type UserClaims struct { jwt.RegisteredClaims Name string `json:"name"` PictureURL string `json:"picture_url"` UserID string `json:"user_id"` Email string `json:"email"` EmailVerified bool `json:"email_verified"` }
UserClaims is a custom claims that contains more user data beside standard claims's data
func GetUserClaims ¶
func GetUserClaims(ctx context.Context) *UserClaims
GetUserClaims returns the authorized user's claims from context