diff --git a/plugins/auth-backend/src/providers/google/provider.ts b/plugins/auth-backend/src/providers/google/provider.ts index 089be9ad3d..b79c6bf362 100644 --- a/plugins/auth-backend/src/providers/google/provider.ts +++ b/plugins/auth-backend/src/providers/google/provider.ts @@ -17,31 +17,12 @@ import passport from 'passport'; import express from 'express'; import { Strategy as GoogleStrategy } from 'passport-google-oauth20'; -import { - AuthProvider, - AuthProviderRouteHandlers, - AuthResponse, -} from './../types'; - -const postMessageResponse = (res: express.Response, data: AuthResponse) => { - const jsonData = JSON.stringify(data); - const base64Data = Buffer.from(jsonData, 'utf8').toString('base64'); - - res.setHeader('X-Frame-Options', 'sameorigin'); - res.end(` - -
- - - - `); -}; +import { AuthProvider, AuthProviderRouteHandlers } from './../types'; +import { postMessageResponse } from './../utils'; export class GoogleAuthProvider implements AuthProvider, AuthProviderRouteHandlers { - providerConfig: any; + private readonly providerConfig: any; constructor(providerConfig: any) { this.providerConfig = providerConfig; } @@ -58,6 +39,7 @@ export class GoogleAuthProvider prompt: 'consent', })(req, res, next); } + frameHandler( req: express.Request, res: express.Response, diff --git a/plugins/auth-backend/src/providers/index.ts b/plugins/auth-backend/src/providers/index.ts index 61b3ecdda7..1ed13cdc33 100644 --- a/plugins/auth-backend/src/providers/index.ts +++ b/plugins/auth-backend/src/providers/index.ts @@ -35,13 +35,13 @@ export const defaultRouter = (provider: AuthProviderRouteHandlers) => { }; export const makeProvider = (config: any) => { - const provider = config.provider; - const ProviderImpl = providerFactories[provider]; + const providerId = config.provider; + const ProviderImpl = providerFactories[providerId]; if (!ProviderImpl) { - throw Error(`Provider Implementation missing for provider: ${provider}`); + throw Error(`Provider Implementation missing for provider: ${providerId}`); } const providerInstance = new ProviderImpl(config); const strategy = providerInstance.strategy(); const providerRouter = defaultRouter(providerInstance); - return { provider, strategy, providerRouter }; + return { providerId, strategy, providerRouter }; }; diff --git a/plugins/auth-backend/src/providers/types.ts b/plugins/auth-backend/src/providers/types.ts index 3b200d906a..fcdfc2bbad 100644 --- a/plugins/auth-backend/src/providers/types.ts +++ b/plugins/auth-backend/src/providers/types.ts @@ -53,7 +53,6 @@ export type AuthProviderFactories = { export type AuthInfo = { profile: passport.Profile; accessToken: string; - refreshToken?: string; expiresAt?: number; }; @@ -64,5 +63,5 @@ export type AuthResponse = } | { type: 'auth-result'; - error: Error | undefined; + error: Error; }; diff --git a/plugins/auth-backend/src/providers/utils.ts b/plugins/auth-backend/src/providers/utils.ts new file mode 100644 index 0000000000..4fbe66361a --- /dev/null +++ b/plugins/auth-backend/src/providers/utils.ts @@ -0,0 +1,37 @@ +/* + * Copyright 2020 Spotify AB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import express from 'express'; +import { AuthResponse } from './types'; + +export const postMessageResponse = ( + res: express.Response, + data: AuthResponse, +) => { + const jsonData = JSON.stringify(data); + const base64Data = Buffer.from(jsonData, 'utf8').toString('base64'); + + res.setHeader('X-Frame-Options', 'sameorigin'); + res.end(` + + + + + + `); +}; diff --git a/plugins/auth-backend/src/service/router.ts b/plugins/auth-backend/src/service/router.ts index f6b476b8dd..dff03e8139 100644 --- a/plugins/auth-backend/src/service/router.ts +++ b/plugins/auth-backend/src/service/router.ts @@ -33,10 +33,12 @@ export async function createRouter( // configure all the providers for (const providerConfig of providers) { - logger.info('Configuring providers'); - const { provider, strategy, providerRouter } = makeProvider(providerConfig); + const { providerId, strategy, providerRouter } = makeProvider( + providerConfig, + ); + logger.info(`Configuring provider: ${providerId}`); passport.use(strategy); - router.use(`/${provider}`, providerRouter); + router.use(`/${providerId}`, providerRouter); } passport.serializeUser((user, done) => {