feat: twitch auth module

pull/835/head
Nick 6 years ago
parent d80bb928f7
commit 849d4f4774

@ -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,

@ -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)
}
}
))
}

@ -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

Loading…
Cancel
Save