From 0e941222c54b1926298dc004530ff347a35a1df0 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 21 Dec 2018 16:26:01 +0000 Subject: [PATCH] [next] Email Login (#2138) * feat: added email scope to google login * feat: enabled email for facebook * fix: added fallback --- .../middleware/passport/strategies/facebook.ts | 10 ++++++++++ .../app/middleware/passport/strategies/google.ts | 4 +++- .../app/middleware/passport/strategies/oauth2.ts | 15 ++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/core/server/app/middleware/passport/strategies/facebook.ts b/src/core/server/app/middleware/passport/strategies/facebook.ts index e79a6ff24..5d12a6b79 100644 --- a/src/core/server/app/middleware/passport/strategies/facebook.ts +++ b/src/core/server/app/middleware/passport/strategies/facebook.ts @@ -29,6 +29,16 @@ export default class FacebookStrategy extends OAuth2Strategy< > { public name = "facebook"; + constructor(options: FacebookStrategyOptions) { + super({ + ...options, + authenticateOptions: { + display: "popup", + scope: ["email"], + }, + }); + } + protected getIntegration = (integrations: GQLAuthIntegrations) => integrations.facebook; diff --git a/src/core/server/app/middleware/passport/strategies/google.ts b/src/core/server/app/middleware/passport/strategies/google.ts index bac03a4af..312cfd020 100644 --- a/src/core/server/app/middleware/passport/strategies/google.ts +++ b/src/core/server/app/middleware/passport/strategies/google.ts @@ -38,7 +38,9 @@ export default class GoogleStrategy extends OAuth2Strategy< constructor(options: GoogleStrategyOptions) { super({ ...options, - scope: ["profile"], + authenticateOptions: { + scope: ["profile", "email"], + }, }); } diff --git a/src/core/server/app/middleware/passport/strategies/oauth2.ts b/src/core/server/app/middleware/passport/strategies/oauth2.ts index e12031f99..bf627bbce 100644 --- a/src/core/server/app/middleware/passport/strategies/oauth2.ts +++ b/src/core/server/app/middleware/passport/strategies/oauth2.ts @@ -21,7 +21,7 @@ export interface OAuth2StrategyOptions { config: Config; mongo: Db; tenantCache: TenantCache; - scope?: string[]; + authenticateOptions?: Record; } export default abstract class OAuth2Strategy< @@ -31,15 +31,20 @@ export default abstract class OAuth2Strategy< protected config: Config; protected mongo: Db; protected cache: TenantCacheAdapter; - private scope?: string[]; + private authenticateOptions: Record; - constructor({ config, mongo, tenantCache, scope }: OAuth2StrategyOptions) { + constructor({ + config, + mongo, + tenantCache, + authenticateOptions, + }: OAuth2StrategyOptions) { super(); this.config = config; this.mongo = mongo; this.cache = new TenantCacheAdapter(tenantCache); - this.scope = scope; + this.authenticateOptions = authenticateOptions || {}; } protected abstract getIntegration(integrations: AuthIntegrations): T; @@ -119,7 +124,7 @@ export default abstract class OAuth2Strategy< strategy.authenticate(req, { session: false, - scope: this.scope, + ...this.authenticateOptions, }); } catch (err) { return this.error(err);