MCPcopy Create free account
hub / github.com/bytebase/bytebase / getTokenCached

Function getTokenCached

backend/plugin/webhook/teams/app.go:130–153  ·  view source on GitHub ↗
(ctx context.Context, c *http.Client, tenantID, clientID, clientSecret, scope string)

Source from the content-addressed store, hash-verified

128}
129
130func getTokenCached(ctx context.Context, c *http.Client, tenantID, clientID, clientSecret, scope string) (string, error) {
131 tokenCacheLock.Lock()
132 defer tokenCacheLock.Unlock()
133
134 key := tokenKey{
135 tenantID: tenantID,
136 clientID: clientID,
137 clientSecret: clientSecret,
138 scope: scope,
139 }
140
141 token, ok := tokenCache.Get(key)
142 if ok && time.Now().Before(token.expireAt.Add(-time.Minute)) {
143 return token.token, nil
144 }
145
146 token, err := getToken(ctx, c, tenantID, clientID, clientSecret, scope)
147 if err != nil {
148 return "", err
149 }
150 tokenCache.Add(key, token)
151
152 return token.token, nil
153}
154
155func (p *provider) refreshGraphToken(ctx context.Context) error {
156 token, err := getTokenCached(ctx, p.c, p.tenantID, p.clientID, p.clientSecret, graphScope)

Callers 2

refreshGraphTokenMethod · 0.70
refreshBotTokenMethod · 0.70

Calls 2

GetMethod · 0.80
getTokenFunction · 0.70

Tested by

no test coverage detected