mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-24 02:39:19 -05:00
chore: apply review suggestions
Co-authored-by: samanhappy <2755122+samanhappy@users.noreply.github.com>
This commit is contained in:
@@ -41,6 +41,8 @@ import {
|
||||
// Import getServerByName to access ServerInfo
|
||||
import { getServerByName } from './mcpService.js';
|
||||
|
||||
const ACCESS_TOKEN_REFRESH_THRESHOLD_MS = 60_000;
|
||||
|
||||
/**
|
||||
* MCPHub OAuth Provider for server-side OAuth flows
|
||||
*
|
||||
@@ -354,7 +356,7 @@ export class MCPHubOAuthProvider implements OAuthClientProvider {
|
||||
// Refresh if token is expired or about to expire
|
||||
const expiresAt = this.getAccessTokenExpiryMs(oauth);
|
||||
const now = Date.now();
|
||||
if (expiresAt && expiresAt - now <= 60_000) {
|
||||
if (expiresAt && expiresAt - now <= ACCESS_TOKEN_REFRESH_THRESHOLD_MS) {
|
||||
const refreshed = await this.refreshAccessTokenIfNeeded(oauth.refreshToken);
|
||||
if (refreshed) {
|
||||
return refreshed;
|
||||
@@ -408,7 +410,7 @@ export class MCPHubOAuthProvider implements OAuthClientProvider {
|
||||
const nextRefreshToken = tokens.refreshToken ?? refreshToken;
|
||||
if (tokens.refreshToken === undefined) {
|
||||
console.warn(
|
||||
`Refresh response missing refresh_token for ${this.serverName}, reusing existing token`,
|
||||
`Refresh response missing refresh_token for ${this.serverName}, reusing existing refresh token`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,18 @@ import * as oauthRegistration from '../../src/services/oauthClientRegistration.j
|
||||
import * as oauthSettingsStore from '../../src/services/oauthSettingsStore.js';
|
||||
|
||||
describe('MCPHubOAuthProvider token refresh', () => {
|
||||
const NOW = 1_700_000_000_000;
|
||||
let nowSpy: jest.SpyInstance<number, []>;
|
||||
|
||||
beforeEach(() => {
|
||||
nowSpy = jest.spyOn(Date, 'now').mockReturnValue(NOW);
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
nowSpy.mockRestore();
|
||||
});
|
||||
|
||||
const baseConfig = {
|
||||
url: 'https://example.com/v1/sse',
|
||||
oauth: {
|
||||
@@ -44,7 +52,7 @@ describe('MCPHubOAuthProvider token refresh', () => {
|
||||
...baseConfig,
|
||||
oauth: {
|
||||
...baseConfig.oauth,
|
||||
accessTokenExpiresAt: Date.now() - 1_000,
|
||||
accessTokenExpiresAt: NOW - 1_000,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -54,7 +62,7 @@ describe('MCPHubOAuthProvider token refresh', () => {
|
||||
...expiredConfig.oauth,
|
||||
accessToken: 'new-access',
|
||||
refreshToken: 'new-refresh',
|
||||
accessTokenExpiresAt: Date.now() + 3_600_000,
|
||||
accessTokenExpiresAt: NOW + 3_600_000,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -83,7 +91,7 @@ describe('MCPHubOAuthProvider token refresh', () => {
|
||||
...baseConfig,
|
||||
oauth: {
|
||||
...baseConfig.oauth,
|
||||
accessTokenExpiresAt: Date.now() + 10 * 60 * 1_000,
|
||||
accessTokenExpiresAt: NOW + 10 * 60 * 1_000,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user