From b421ba6b8dba09edda935a8a4fbf5c3771fefd9d Mon Sep 17 00:00:00 2001 From: Raghunandan Date: Thu, 18 Jun 2020 13:55:03 +0200 Subject: [PATCH] review fixes --- packages/core-api/src/apis/definitions/auth.ts | 4 ++-- .../auth-backend/src/lib/EnvironmentHandler.ts | 4 +++- .../src/lib/PassportStrategyHelper.ts | 3 ++- plugins/auth-backend/src/providers/factories.ts | 4 +++- plugins/auth-backend/src/providers/types.ts | 15 +++++++++++---- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/core-api/src/apis/definitions/auth.ts b/packages/core-api/src/apis/definitions/auth.ts index a9b82cefc7..c884bf975b 100644 --- a/packages/core-api/src/apis/definitions/auth.ts +++ b/packages/core-api/src/apis/definitions/auth.ts @@ -158,14 +158,14 @@ export type ProfileInfoOptions = { }; /** - * This API provides access to profile information of the signed in user. + * This API provides access to profile information of the user from an auth provider. */ export type ProfileInfoApi = { getProfile(options?: ProfileInfoOptions): Promise; }; /** - * Profile information of a signed in user. + * Profile information of the user from an auth provider. */ export type ProfileInfo = { /** diff --git a/plugins/auth-backend/src/lib/EnvironmentHandler.ts b/plugins/auth-backend/src/lib/EnvironmentHandler.ts index c4d8d2b6e7..6c16b3a712 100644 --- a/plugins/auth-backend/src/lib/EnvironmentHandler.ts +++ b/plugins/auth-backend/src/lib/EnvironmentHandler.ts @@ -57,6 +57,8 @@ export class EnvironmentHandler implements AuthProviderRouteHandlers { async logout(req: express.Request, res: express.Response): Promise { const provider = this.getProviderForEnv(req); - await provider.logout(req, res); + if (provider.logout) { + await provider.logout(req, res); + } } } diff --git a/plugins/auth-backend/src/lib/PassportStrategyHelper.ts b/plugins/auth-backend/src/lib/PassportStrategyHelper.ts index 6fa65d01da..1e8dfca5ed 100644 --- a/plugins/auth-backend/src/lib/PassportStrategyHelper.ts +++ b/plugins/auth-backend/src/lib/PassportStrategyHelper.ts @@ -21,6 +21,7 @@ import { RedirectInfo, RefreshTokenResponse, ProfileInfo, + ProviderStrategy, } from '../providers/types'; export const makeProfileInfo = ( @@ -153,7 +154,7 @@ export const executeFetchUserProfileStrategy = async ( params: any, ): Promise => { return new Promise((resolve, reject) => { - const anyStrategy = providerStrategy as any; + const anyStrategy = (providerStrategy as unknown) as ProviderStrategy; anyStrategy.userProfile( accessToken, (error: Error, passportProfile: passport.Profile) => { diff --git a/plugins/auth-backend/src/providers/factories.ts b/plugins/auth-backend/src/providers/factories.ts index 4cc9212620..b5e59b713b 100644 --- a/plugins/auth-backend/src/providers/factories.ts +++ b/plugins/auth-backend/src/providers/factories.ts @@ -44,7 +44,9 @@ export const createAuthProviderRouter = ( router.get('/start', provider.start.bind(provider)); router.get('/handler/frame', provider.frameHandler.bind(provider)); router.post('/handler/frame', provider.frameHandler.bind(provider)); - router.post('/logout', provider.logout.bind(provider)); + if (provider.logout) { + router.post('/logout', provider.logout.bind(provider)); + } if (provider.refresh) { router.get('/refresh', provider.refresh.bind(provider)); } diff --git a/plugins/auth-backend/src/providers/types.ts b/plugins/auth-backend/src/providers/types.ts index 074c78663e..7c16436021 100644 --- a/plugins/auth-backend/src/providers/types.ts +++ b/plugins/auth-backend/src/providers/types.ts @@ -34,12 +34,15 @@ export type OAuthProviderOptions = { export type OAuthProviderConfig = { /** - * If the cookies set by the provider have to be marked secure. For development environment - * we don't mark the cookie as secure. + * Cookies can be marked with a secure flag to send cookies only when the request + * is over an encrypted channel (HTTPS). + * + * For development environment we don't mark the cookie as secure since we serve + * localhost over HTTP. */ secure: boolean; /** - * The domain:port where the app (frontend) is hosted. This is used to post messages back + * The protocol://domain[:port] where the app (frontend) is hosted. This is used to post messages back * to the window that initiates an auth request. */ appOrigin: string; @@ -68,7 +71,7 @@ export type EnvironmentProviderConfig = { export type AuthProviderConfig = { /** - * The domain:port where the app is hosted. This is used to construct the + * The protocol://domain[:port] where the app is hosted. This is used to construct the * callbackURL to redirect to once the user signs in to the auth provider. */ baseUrl: string; @@ -261,6 +264,10 @@ export type RefreshTokenResponse = { params: any; }; +export type ProviderStrategy = { + userProfile(accessToken: string, callback: Function): void; +}; + export type SAMLProviderConfig = { entryPoint: string; issuer: string;