From 786a00d6d0fa5bb7b0e44ecef39814fe314a0cd8 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 22 May 2020 12:27:27 +0200 Subject: [PATCH 1/3] plugins/auth-backend: pass on scope string as is to google provider --- plugins/auth-backend/src/providers/google/provider.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/auth-backend/src/providers/google/provider.ts b/plugins/auth-backend/src/providers/google/provider.ts index 2c559a2dc9..1e0ed83234 100644 --- a/plugins/auth-backend/src/providers/google/provider.ts +++ b/plugins/auth-backend/src/providers/google/provider.ts @@ -23,6 +23,7 @@ import { AuthProviderConfig, } from './../types'; import { postMessageResponse } from './../utils'; +import { InputError } from '@backstage/backend-common'; export class GoogleAuthProvider implements AuthProvider, AuthProviderRouteHandlers { @@ -36,9 +37,12 @@ export class GoogleAuthProvider res: express.Response, next: express.NextFunction, ) { - const scopes = req.query.scopes?.toString().split(','); + const scope = req.query.scope?.toString() ?? ''; + if (!scope) { + throw new InputError('missing scope parameter'); + } return passport.authenticate('google', { - scope: scopes, + scope, accessType: 'offline', prompt: 'consent', })(req, res, next); From 73c555f41dcc59a137f9cd5ab255bfaafac50f4d Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 22 May 2020 12:30:02 +0200 Subject: [PATCH 2/3] plugins/auth-backend: forward id token to auth session --- plugins/auth-backend/src/providers/google/provider.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/auth-backend/src/providers/google/provider.ts b/plugins/auth-backend/src/providers/google/provider.ts index 1e0ed83234..5d715724bf 100644 --- a/plugins/auth-backend/src/providers/google/provider.ts +++ b/plugins/auth-backend/src/providers/google/provider.ts @@ -70,15 +70,20 @@ export class GoogleAuthProvider strategy(): passport.Strategy { return new GoogleStrategy( - { ...this.providerConfig.options, passReqToCallback: true }, + { ...this.providerConfig.options }, ( - _req: any, accessToken: any, refreshToken: any, + params: any, profile: any, cb: any, ) => { - cb(undefined, { profile, accessToken, refreshToken }); + cb(undefined, { + profile, + idToken: params.id_token, + accessToken, + refreshToken, + }); }, ); } From 1d43ee5b1d79455f4fc8764cd091d47dd6c19f92 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 22 May 2020 12:32:51 +0200 Subject: [PATCH 3/3] plugins/auth-backend: fix for post message response not being html + close automatically --- plugins/auth-backend/src/providers/utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/auth-backend/src/providers/utils.ts b/plugins/auth-backend/src/providers/utils.ts index 4fbe66361a..7fb906ad7c 100644 --- a/plugins/auth-backend/src/providers/utils.ts +++ b/plugins/auth-backend/src/providers/utils.ts @@ -24,12 +24,16 @@ export const postMessageResponse = ( const jsonData = JSON.stringify(data); const base64Data = Buffer.from(jsonData, 'utf8').toString('base64'); + res.setHeader('Content-Type', 'text/html'); res.setHeader('X-Frame-Options', 'sameorigin'); + + // TODO: Make target app origin configurable globally res.end(`