@things-factory/auth-google 6.1.186 → 6.1.188

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/auth-google",
3
- "version": "6.1.186",
3
+ "version": "6.1.188",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -34,5 +34,5 @@
34
34
  "passport": "^0.6.0",
35
35
  "passport-google-oauth20": "^2.0.0"
36
36
  },
37
- "gitHead": "ddf508496cdd7d4b9d0e020703a2f7a586a42ec5"
37
+ "gitHead": "ae62986a327cfe158261052f0ae4f4586d4de55c"
38
38
  }
@@ -16,11 +16,11 @@ export async function syncAllUserInfo(authProvider: AuthProvider, context: Resol
16
16
  }
17
17
  }).then(res => res.json())
18
18
 
19
- latestData.value
20
- .filter(({ mail }) => mail)
21
- .forEach(async user => {
19
+ for (const user of latestData.value) {
20
+ if (user.mail) {
22
21
  await updateUserInfo(authProvider, user, context)
23
- })
22
+ }
23
+ }
24
24
  }
25
25
 
26
26
  export async function updateUserInfo(authProvider: AuthProvider, userInfo, context: ResolverContext) {
@@ -8,27 +8,35 @@ const SSOGoogleConfig = config.get('sso/google/config')
8
8
 
9
9
  if (SSOGoogleConfig) {
10
10
  passport.use(
11
- new GoogleStrategy(SSOGoogleConfig, async (token, tokenSecret, profile, done) => {
12
- if (!profile) {
13
- return done(new Error('No profile found'), null)
14
- }
11
+ new GoogleStrategy(
12
+ {
13
+ ...SSOGoogleConfig,
14
+ scope: ['profile', 'https://www.googleapis.com/auth/userinfo.email']
15
+ },
16
+ async (token, tokenSecret, profile, done) => {
17
+ if (!profile) {
18
+ return done(new Error('No profile found'), null)
19
+ }
15
20
 
16
- try {
17
- const { email } = profile
21
+ try {
22
+ const { emails, photos } = profile
23
+ const email = emails?.[0].value
24
+ const photo = photos?.[0].value
18
25
 
19
- const user = await User.checkAuthWithEmail({ email })
26
+ const user = await User.checkAuthWithEmail({ email })
20
27
 
21
- const { id, userType, status } = user
28
+ const { id, userType, status } = user
22
29
 
23
- return done(null, {
24
- id,
25
- userType,
26
- status
27
- })
28
- } catch (error) {
29
- return done(error)
30
+ return done(null, {
31
+ id,
32
+ userType,
33
+ status
34
+ })
35
+ } catch (error) {
36
+ return done(error)
37
+ }
30
38
  }
31
- })
39
+ )
32
40
  )
33
41
  }
34
42
 
package/server/routes.ts CHANGED
@@ -21,7 +21,7 @@ if (SSOGoogleConfig) {
21
21
  globalPublicRouter.get(
22
22
  '/auth/signin-with-google',
23
23
  passport.authenticate('google', {
24
- scope: ['https://www.googleapis.com/auth/plus.login']
24
+ scope: ['profile', 'https://www.googleapis.com/auth/userinfo.email']
25
25
  })
26
26
  )
27
27
  })