MCPcopy Create free account
hub / github.com/Waishnav/devspace / issueTokens

Method issueTokens

src/oauth-provider.ts:274–316  ·  view source on GitHub ↗
(
    clientId: string,
    scopes: string[],
    resource?: URL,
    consumedRefreshTokenHash?: string,
  )

Source from the content-addressed store, hash-verified

272 }
273
274 private issueTokens(
275 clientId: string,
276 scopes: string[],
277 resource?: URL,
278 consumedRefreshTokenHash?: string,
279 ): OAuthTokens {
280 const now = Math.floor(Date.now() / 1000);
281 const accessToken = randomToken();
282 const refreshToken = randomToken();
283 const accessExpiresAt = now + this.config.accessTokenTtlSeconds;
284 const refreshExpiresAt = now + this.config.refreshTokenTtlSeconds;
285
286 const saved = this.oauthStore.saveTokenPair(
287 {
288 accessTokenHash: hashToken(accessToken),
289 accessToken: {
290 clientId,
291 scopes,
292 expiresAt: accessExpiresAt,
293 resource: resource?.href,
294 },
295 refreshTokenHash: hashToken(refreshToken),
296 refreshToken: {
297 clientId,
298 scopes,
299 expiresAt: refreshExpiresAt,
300 resource: resource?.href,
301 },
302 },
303 consumedRefreshTokenHash,
304 );
305 if (!saved) {
306 throw new InvalidGrantError("Invalid refresh token");
307 }
308
309 return {
310 access_token: accessToken,
311 token_type: "bearer",
312 expires_in: this.config.accessTokenTtlSeconds,
313 refresh_token: refreshToken,
314 scope: scopes.join(" "),
315 };
316 }
317}
318
319function authorizationFormFields(

Callers 2

exchangeRefreshTokenMethod · 0.95

Calls 3

randomTokenFunction · 0.85
saveTokenPairMethod · 0.80
hashTokenFunction · 0.70

Tested by

no test coverage detected