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

View File

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

View File

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