AuthenticateSimpleKiteKey authenticates user from the given kite key and returns the authenticated username. It's the same as AuthenticateFromKiteKey but can be used without the need for a *kite.Request.
(key string)
| 297 | // returns the authenticated username. It's the same as AuthenticateFromKiteKey |
| 298 | // but can be used without the need for a *kite.Request. |
| 299 | func (k *Kite) AuthenticateSimpleKiteKey(key string) (string, error) { |
| 300 | claims := &kitekey.KiteClaims{} |
| 301 | |
| 302 | token, err := jwt.ParseWithClaims(key, claims, k.verify) |
| 303 | if err != nil { |
| 304 | return "", err |
| 305 | } |
| 306 | |
| 307 | if !token.Valid { |
| 308 | return "", errors.New("Invalid signature in token") |
| 309 | } |
| 310 | |
| 311 | if claims.Subject == "" { |
| 312 | return "", errors.New("token has no username") |
| 313 | } |
| 314 | |
| 315 | return claims.Subject, nil |
| 316 | } |
| 317 | |
| 318 | func (k *Kite) verifyInit() { |
| 319 | k.configMu.Lock() |