parse the token string and set
(tokenString string)
| 39 | |
| 40 | // parse the token string and set |
| 41 | func (t *TokenRenewer) parse(tokenString string) error { |
| 42 | claims := &kitekey.KiteClaims{} |
| 43 | |
| 44 | _, err := jwt.ParseWithClaims(tokenString, claims, t.localKite.RSAKey) |
| 45 | if err != nil { |
| 46 | valErr, ok := err.(*jwt.ValidationError) |
| 47 | if !ok { |
| 48 | return err |
| 49 | } |
| 50 | |
| 51 | // do noy return for ValidationErrorSignatureValid. This is because we |
| 52 | // might asked for a kite who's public Key is different what we have. |
| 53 | // We still should be able to send them requests. |
| 54 | if (valErr.Errors & jwt.ValidationErrorSignatureInvalid) == 0 { |
| 55 | return fmt.Errorf("Cannot parse token: %s", err) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | t.validUntil = time.Unix(claims.ExpiresAt, 0).UTC() |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | // RenewWhenExpires renews the token before it expires. |
| 64 | func (t *TokenRenewer) RenewWhenExpires() { |
no outgoing calls
no test coverage detected