diff --git a/plugins/auth-backend/src/providers/auth0/provider.ts b/plugins/auth-backend/src/providers/auth0/provider.ts index 3321ff38af..3726fe10c0 100644 --- a/plugins/auth-backend/src/providers/auth0/provider.ts +++ b/plugins/auth-backend/src/providers/auth0/provider.ts @@ -43,11 +43,10 @@ import { AuthResolverContext, } from '../types'; import { createAuthProviderIntegration } from '../createAuthProviderIntegration'; -import { ExtraVerificationParams } from 'passport-auth0'; +import { StateStore } from 'passport-oauth2'; type PrivateInfo = { refreshToken: string; - extraParams: ExtraVerificationParams; }; export type Auth0AuthProviderOptions = OAuthProviderOptions & { @@ -65,6 +64,23 @@ export class Auth0AuthProvider implements OAuthHandlers { private readonly resolverContext: AuthResolverContext; private readonly audience?: string; + /** + * Due to passport-auth0 forcing options.state = true, + * passport-oauth2 requires express-session to be installed + * so that the 'state' parameter of the oauth2 flow can be stored. + * This implementation of StateStore matches the NullStore found within + * passport-oauth2, which is the StateStore implementation used when options.state = false, + * allowing us to avoid using express-session in order to integrate with Okta. + */ + private store: StateStore = { + store(_req: express.Request, cb: any) { + cb(null, null); + }, + verify(_req: express.Request, _state: string, cb: any) { + cb(null, true); + }, + }; + constructor(options: Auth0AuthProviderOptions) { this.signInResolver = options.signInResolver; this.authHandler = options.authHandler; @@ -79,12 +95,12 @@ export class Auth0AuthProvider implements OAuthHandlers { // We need passReqToCallback set to false to get params, but there's // no matching type signature for that, so instead behold this beauty passReqToCallback: false as true, + store: this.store, }, ( accessToken: any, refreshToken: any, params: any, - extraParams: ExtraVerificationParams, fullProfile: passport.Profile, done: PassportDoneCallback, ) => { @@ -97,8 +113,7 @@ export class Auth0AuthProvider implements OAuthHandlers { params, }, { - refreshToken, - extraParams, + refreshToken }, ); }, diff --git a/plugins/auth-backend/src/providers/auth0/strategy.ts b/plugins/auth-backend/src/providers/auth0/strategy.ts index bef2836ab5..cf5b522ec5 100644 --- a/plugins/auth-backend/src/providers/auth0/strategy.ts +++ b/plugins/auth-backend/src/providers/auth0/strategy.ts @@ -14,6 +14,7 @@ * limitations under the License. */ import Auth0InternalStrategy from 'passport-auth0'; +import { StateStore } from 'passport-oauth2'; export interface Auth0StrategyOptionsWithRequest { clientID: string; @@ -21,12 +22,13 @@ export interface Auth0StrategyOptionsWithRequest { callbackURL: string; domain: string; passReqToCallback: true; + store: StateStore; } export default class Auth0Strategy extends Auth0InternalStrategy { constructor( options: Auth0StrategyOptionsWithRequest, - verify: Auth0InternalStrategy.VerifyFunctionWithRequest, + verify: Auth0InternalStrategy.VerifyFunction, ) { const optionsWithURLs = { ...options,