Using req instead of state

Signed-off-by: Nicolas Arnold <nic@roadie.io>
This commit is contained in:
Nicolas Arnold
2021-10-26 09:57:26 +01:00
parent 118df0f94d
commit f18755ee49
3 changed files with 11 additions and 12 deletions
@@ -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',
@@ -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<RedirectInfo> {
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,
+2 -2
View File
@@ -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<AuthResult> = (
) => Promise<AuthHandlerResult>;
export type StateEncoder = (
input: OAuthState,
req: OAuthStartRequest,
) => Promise<{ encodedState: string }>;