diff --git a/plugins/auth-backend/src/providers/github/provider.test.ts b/plugins/auth-backend/src/providers/github/provider.test.ts index 44467ce66c..e418ab22c2 100644 --- a/plugins/auth-backend/src/providers/github/provider.test.ts +++ b/plugins/auth-backend/src/providers/github/provider.test.ts @@ -25,7 +25,7 @@ import { } from './provider'; import * as helpers from '../../lib/passport/PassportStrategyHelper'; import { makeProfileInfo } from '../../lib/passport/PassportStrategyHelper'; -import { OAuthState, encodeState } from '../../lib/oauth'; +import { OAuthStartRequest, encodeState } from '../../lib/oauth'; const mockFrameHandler = jest.spyOn( helpers, @@ -57,8 +57,8 @@ describe('GithubAuthProvider', () => { authHandler: async ({ fullProfile }) => ({ profile: makeProfileInfo(fullProfile), }), - stateEncoder: async (state: OAuthState) => ({ - encodedState: encodeState(state), + stateEncoder: async (req: OAuthStartRequest) => ({ + encodedState: encodeState(req.state), }), callbackUrl: 'mock', clientId: 'mock', diff --git a/plugins/auth-backend/src/providers/github/provider.ts b/plugins/auth-backend/src/providers/github/provider.ts index bc81e61a10..c7e82cc5ff 100644 --- a/plugins/auth-backend/src/providers/github/provider.ts +++ b/plugins/auth-backend/src/providers/github/provider.ts @@ -42,7 +42,6 @@ import { encodeState, OAuthRefreshRequest, OAuthResponse, - OAuthState, } from '../../lib/oauth'; import { CatalogIdentityClient } from '../../lib/catalog'; import { TokenIssuer } from '../../identity'; @@ -114,7 +113,7 @@ export class GithubAuthProvider implements OAuthHandlers { async start(req: OAuthStartRequest): Promise { return await executeRedirectStrategy(req, this._strategy, { scope: req.scope, - state: (await this.stateEncoder(req.state)).encodedState, + state: (await this.stateEncoder(req)).encodedState, }); } @@ -286,11 +285,11 @@ export const createGithubProvider = ( logger, }); - const stateEncoder: StateEncoder = options?.stateEncoder - ? options.stateEncoder - : async (state: OAuthState): Promise<{ encodedState: string }> => { - return { encodedState: encodeState(state) }; - }; + const stateEncoder: StateEncoder = + options?.stateEncoder ?? + (async (req: OAuthStartRequest): Promise<{ encodedState: string }> => { + return { encodedState: encodeState(req.state) }; + }); const provider = new GithubAuthProvider({ clientId, diff --git a/plugins/auth-backend/src/providers/types.ts b/plugins/auth-backend/src/providers/types.ts index 09e1935f3e..089c82b293 100644 --- a/plugins/auth-backend/src/providers/types.ts +++ b/plugins/auth-backend/src/providers/types.ts @@ -21,7 +21,7 @@ import { Config } from '@backstage/config'; import express from 'express'; import { Logger } from 'winston'; import { TokenIssuer } from '../identity/types'; -import { OAuthState } from '../lib/oauth/types'; +import { OAuthStartRequest } from '../lib/oauth/types'; import { CatalogIdentityClient } from '../lib/catalog'; export type AuthProviderConfig = { @@ -226,5 +226,5 @@ export type AuthHandler = ( ) => Promise; export type StateEncoder = ( - input: OAuthState, + req: OAuthStartRequest, ) => Promise<{ encodedState: string }>;