cacheToken cached the signed token under the given key. It also ensures the token is invalidated after its expiration time. If the token was already exists in the cache, it will be overwritten with a new value.
(key, signed string)
| 541 | // If the token was already exists in the cache, it will be |
| 542 | // overwritten with a new value. |
| 543 | func (k *Kontrol) cacheToken(key, signed string) { |
| 544 | if ct, ok := k.tokenCache[key]; ok { |
| 545 | ct.timer.Stop() |
| 546 | } |
| 547 | |
| 548 | k.tokenCache[key] = cachedToken{ |
| 549 | signed: signed, |
| 550 | timer: time.AfterFunc(k.tokenTTL()-k.tokenLeeway(), func() { |
| 551 | k.tokenCacheMu.Lock() |
| 552 | delete(k.tokenCache, key) |
| 553 | k.tokenCacheMu.Unlock() |
| 554 | }), |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | // generateToken returns a JWT token string. Please see the URL for details: |
| 559 | // http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-13#section-4.1 |
no test coverage detected