diff --git a/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts b/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts index d20eaa54cb..d75bceef97 100644 --- a/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts +++ b/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts @@ -20,7 +20,7 @@ import { GithubSession } from './types'; import { OAuthApi, AccessTokenOptions } from '../../../definitions/auth'; import { OAuthRequestApi, AuthProvider } from '../../../definitions'; import { SessionManager } from '../../../../lib/AuthSessionManager/types'; -import { RefreshingAuthSessionManager } from '../../../../lib/AuthSessionManager'; +import { StaticAuthSessionManager } from '../../../../lib/AuthSessionManager'; type CreateOptions = { // TODO(Rugvip): These two should be grabbed from global config when available, they're not unique to GithubAuth @@ -63,20 +63,16 @@ class GithubAuth implements OAuthApi { sessionTransform(res: GithubAuthResponse): GithubSession { return { accessToken: res.accessToken, - scopes: GithubAuth.normalizeScopes(res.scope), + scopes: GithubAuth.normalizeScope(res.scope), expiresAt: new Date(Date.now() + res.expiresInSeconds * 1000), }; }, }); - const sessionManager = new RefreshingAuthSessionManager({ + const sessionManager = new StaticAuthSessionManager({ connector, defaultScopes: new Set(['user']), sessionScopes: session => session.scopes, - sessionShouldRefresh: session => { - const expiresInSec = (session.expiresAt.getTime() - Date.now()) / 1000; - return expiresInSec < 60 * 5; - }, }); return new GithubAuth(sessionManager); @@ -84,11 +80,8 @@ class GithubAuth implements OAuthApi { constructor(private readonly sessionManager: SessionManager) {} - async getAccessToken( - scope?: string | string[], - options?: AccessTokenOptions, - ) { - const normalizedScopes = GithubAuth.normalizeScopes(scope); + async getAccessToken(scope?: string, options?: AccessTokenOptions) { + const normalizedScopes = GithubAuth.normalizeScope(scope); const session = await this.sessionManager.getSession({ ...options, scopes: normalizedScopes, @@ -103,14 +96,14 @@ class GithubAuth implements OAuthApi { await this.sessionManager.removeSession(); } - static normalizeScopes(scopes?: string | string[]): Set { - if (!scopes) { + static normalizeScope(scope?: string): Set { + if (!scope) { return new Set(); } - const scopeList = Array.isArray(scopes) - ? scopes - : scopes.split(/[\s]/).filter(Boolean); + const scopeList = Array.isArray(scope) + ? scope + : scope.split(/[\s|,]/).filter(Boolean); return new Set(scopeList); } diff --git a/packages/core-api/src/lib/AuthSessionManager/index.ts b/packages/core-api/src/lib/AuthSessionManager/index.ts index 426c514646..16a8d3c378 100644 --- a/packages/core-api/src/lib/AuthSessionManager/index.ts +++ b/packages/core-api/src/lib/AuthSessionManager/index.ts @@ -15,4 +15,5 @@ */ export { RefreshingAuthSessionManager } from './RefreshingAuthSessionManager'; +export { StaticAuthSessionManager } from './StaticAuthSessionManager'; export * from './types'; diff --git a/plugins/auth-backend/src/providers/github/provider.ts b/plugins/auth-backend/src/providers/github/provider.ts index 1e8022e1cc..4445e98451 100644 --- a/plugins/auth-backend/src/providers/github/provider.ts +++ b/plugins/auth-backend/src/providers/github/provider.ts @@ -19,7 +19,6 @@ import { Strategy as GithubStrategy } from 'passport-github2'; import { executeFrameHandlerStrategy, executeRedirectStrategy, - executeRefreshTokenStrategy, } from '../PassportStrategyHelper'; import { OAuthProviderHandlers, @@ -37,23 +36,13 @@ export class GithubAuthProvider implements OAuthProviderHandlers { this.providerConfig = providerConfig; this._strategy = new GithubStrategy( { ...this.providerConfig.options }, - ( - accessToken: any, - refreshToken: any, - params: any, - profile: any, - done: any, - ) => { - done( - undefined, - { - profile, - accessToken, - scope: 'user', // params.scope is an empty string here for some reason, so hardcoding for now - expiresInSeconds: params.expires_in, - }, - { refreshToken }, - ); + (accessToken: any, _: any, params: any, profile: any, done: any) => { + done(undefined, { + profile, + accessToken, + scope: params.scope, + expiresInSeconds: params.expires_in, + }); }, ); } @@ -67,18 +56,4 @@ export class GithubAuthProvider implements OAuthProviderHandlers { ): Promise<{ user: AuthInfoBase; info: AuthInfoPrivate }> { return await executeFrameHandlerStrategy(req, this._strategy); } - - async refresh(refreshToken: string, scope: string): Promise { - const { accessToken, params } = await executeRefreshTokenStrategy( - this._strategy, - refreshToken, - scope, - ); - - return { - accessToken, - expiresInSeconds: params.expires_in, - scope: params.scope, - }; - } }