func (u *User) SetToken() { authBackend := utils.InitJWTAuthenticationBackend() token, err := authBackend.GenerateToken(u.Id) if err != nil { panic(err) } u.Token = string(token) }
func getTokenFromJWTBackend(accessToken string) *jwt.Token { authBackend := utils.InitJWTAuthenticationBackend() token, err := jwt.Parse(accessToken, func(token *jwt.Token) (interface{}, error) { if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok { return nil, fmt.Errorf("Unexpected signign method: %v", token.Header["alg"]) } else { return authBackend.PublicKey, nil } }) if err != nil { return nil } return token }