(ctx context.Context, c *http.Client, id, secret string)
| 144 | }() |
| 145 | |
| 146 | func getTokenCached(ctx context.Context, c *http.Client, id, secret string) (string, error) { |
| 147 | tokenCacheLock.Lock() |
| 148 | defer tokenCacheLock.Unlock() |
| 149 | |
| 150 | key := tokenKey{ |
| 151 | id: id, |
| 152 | secret: secret, |
| 153 | } |
| 154 | |
| 155 | token, ok := tokenCache.Get(key) |
| 156 | if ok && time.Now().Before(token.expireAt.Add(-time.Minute)) { |
| 157 | return token.token, nil |
| 158 | } |
| 159 | |
| 160 | token, err := getToken(ctx, c, id, secret) |
| 161 | if err != nil { |
| 162 | return "", err |
| 163 | } |
| 164 | tokenCache.Add(key, token) |
| 165 | |
| 166 | return token.token, nil |
| 167 | } |
| 168 | |
| 169 | func (p *provider) refreshToken(ctx context.Context) error { |
| 170 | token, err := getTokenCached(ctx, p.c, p.id, p.secret) |
no test coverage detected