This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/server/social.js

90 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-02-12 09:28:56 -08:00
module.exports.config = {
2020-11-02 10:31:05 -08:00
defaults: {
origin: process.env.BASE_URL,
transport: 'session',
state: true,
prefix: '/api/connect',
scope: ['email'],
response: ['tokens', 'raw', 'profile'],
},
twitter: {
key: process.env.TWITTER_KEY,
secret: process.env.TWITTER_SECRET,
callback: '/api/user/social/twitter',
profile_url: 'https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true',
},
facebook: {
key: process.env.FACEBOOK_KEY,
secret: process.env.FACEBOOK_SECRET,
callback: '/api/user/social/facebook',
profile_url: 'https://graph.facebook.com/me?fields=email,name,picture'
},
google: {
key: process.env.GOOGLE_KEY,
secret: process.env.GOOGLE_SECRET,
callback: '/api/user/social/google',
2021-11-30 12:24:42 -08:00
},
discord: {
key: process.env.DISCORD_KEY,
secret: process.env.DISCORD_SECRET,
callback: '/api/user/social/discord',
scope: ['identify', 'email'],
},
2021-12-05 11:56:39 -08:00
// non-grant, but things break if it's not there
mastodon: {},
2020-11-02 10:31:05 -08:00
}
2020-11-02 12:45:45 -08:00
2022-02-12 09:28:56 -08:00
module.exports.handlers = {
2020-11-02 12:45:45 -08:00
twitter(r) {
return {
id: r.profile.id_str,
email: r.profile.email,
name: r.profile.screen_name,
avatar: r.profile.profile_image_url_https.replace('_normal', '_400x400'),
access_token: r.access_token,
access_secret: r.access_secret,
}
},
facebook(r) {
return {
id: r.profile.id,
email: r.profile.email,
name: r.profile.name,
avatar: r.profile.picture.data.url,
access_token: r.access_token,
access_secret: r.access_secret,
}
},
google(r) {
return {
id: r.profile.sub,
email: r.profile.email_verified !== false ? r.profile.email : undefined,
name: r.profile.email,
avatar: r.profile.picture,
access_token: r.access_token,
access_secret: r.access_secret,
}
},
2021-11-30 12:24:42 -08:00
discord(r) {
return {
id: r.profile.id,
email: r.profile.email,
name: r.profile.username,
avatar: `https://cdn.discordapp.com/avatars/${r.profile.id}/${r.profile.avatar}`,
access_token: r.access_token,
access_secret: r.access_secret,
}
},
2021-12-05 11:56:39 -08:00
mastodon(r) {
const acct = `${r.profile.username}@${r.instance}`;
return {
id: acct,
2021-12-12 15:30:26 -08:00
// very possibly not really operated by the user
email: acct,
2021-12-05 11:56:39 -08:00
name: acct,
avatar: r.profile.avatar,
access_token: r.access_token,
};
},
2020-11-02 12:45:45 -08:00
};