Skip to content

Commit

Permalink
feat: twitch auth module
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Apr 28, 2019
1 parent d80bb92 commit 849d4f4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions server/models/users.js
Expand Up @@ -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
})

Expand Down Expand Up @@ -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,
Expand Down
23 changes: 15 additions & 8 deletions server/modules/authentication/twitch/authentication.js
Expand Up @@ -5,21 +5,28 @@
// ------------------------------------

const TwitchStrategy = require('passport-twitch').Strategy
const _ = require('lodash')

module.exports = {
init (passport, conf) {
passport.use('twitch',
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)
}
}
))
}
Expand Down
4 changes: 3 additions & 1 deletion server/modules/authentication/twitch/definition.yml
Expand Up @@ -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
Expand Down

0 comments on commit 849d4f4

Please sign in to comment.