Bläddra i källkod

feat: twitch auth module

Nick 6 år sedan
förälder
incheckning
849d4f4774

+ 2 - 2
server/models/users.js

@@ -160,7 +160,7 @@ module.exports = class User extends Model {
 
     // Find existing user
     let user = await WIKI.models.users.query().findOne({
-      providerId: profile.id,
+      providerId: _.toString(profile.id),
       providerKey
     })
 
@@ -224,7 +224,7 @@ module.exports = class User extends Model {
       // Create account
       user = await WIKI.models.users.query().insertAndFetch({
         providerKey: providerKey,
-        providerId: profile.id,
+        providerId: _.toString(profile.id),
         email: primaryEmail,
         name: displayName,
         pictureUrl: pictureUrl,

+ 15 - 8
server/modules/authentication/twitch/authentication.js

@@ -5,6 +5,7 @@
 // ------------------------------------
 
 const TwitchStrategy = require('passport-twitch').Strategy
+const _ = require('lodash')
 
 module.exports = {
   init (passport, conf) {
@@ -12,14 +13,20 @@ module.exports = {
       new TwitchStrategy({
         clientID: conf.clientId,
         clientSecret: conf.clientSecret,
-        callbackURL: conf.callbackURL,
-        scope: 'user_read'
-      }, function (accessToken, refreshToken, profile, cb) {
-        WIKI.models.users.processProfile(profile).then((user) => {
-          return cb(null, user) || true
-        }).catch((err) => {
-          return cb(err, null) || true
-        })
+        callbackURL: conf.callbackURL
+      }, async (accessToken, refreshToken, profile, cb) => {
+        try {
+          const user = await WIKI.models.users.processProfile({
+            profile: {
+              ...profile,
+              picture: _.get(profile, '_json.logo', '')
+            },
+            providerKey: 'twitch'
+          })
+          cb(null, user)
+        } catch (err) {
+          cb(err, null)
+        }
       }
       ))
   }

+ 3 - 1
server/modules/authentication/twitch/definition.yml

@@ -5,8 +5,10 @@ author: requarks.io
 logo: https://static.requarks.io/logo/twitch.svg
 color: indigo darken-2
 website: https://dev.twitch.tv/docs/authentication/
-isAvailable: false
+isAvailable: true
 useForm: false
+scopes:
+  - user_read
 props:
   clientId:
     type: String