// TokenResponse uses the toki JWT generator library to create a new JWT. // The resulting JWT is then set as the resonse token func (auth *Authenticator) TokenResponse(userInfo map[string]interface{}) { auth.GenerateSecret() tokenizer := toki.NewJsonWebToken() tokenizer.TokenAlgorithm = auth.ResolveAlgorithm() // Set the token contents tokenizer.Claim.Content = auth.TokenBody(userInfo) // Sign the token and return the full token string tokenizer.Sign(auth.Secret) token, err := tokenizer.String() if err == nil { // Cache the token info for validation purposes err = auth.CacheTokenInfo() // When token info is cached respond with the token if err == nil { auth.Response.Status = http.StatusOK auth.Response.Token = token } } if err != nil { auth.NewError(http.StatusUnauthorized, err.Error()) } }
func (creds *Credentials) parseToken() error { creds.Jwt = toki.NewJsonWebToken() err := creds.Jwt.Parse(creds.Token) return err }