feat: twitch auth module

This commit is contained in:
Nick 2019-04-28 14:11:27 -04:00
parent d80bb928f7
commit 849d4f4774
3 changed files with 20 additions and 11 deletions

View File

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

View File

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

View File

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