Skip to content

Instantly share code, notes, and snippets.

@kamescg
Last active June 6, 2018 14:56
Show Gist options
  • Save kamescg/5bda6f0e7e7a6da77c2f071e4847f526 to your computer and use it in GitHub Desktop.
Save kamescg/5bda6f0e7e7a6da77c2f071e4847f526 to your computer and use it in GitHub Desktop.
Twitter Verification | uPort Firebase Cloud Function
**
* VerifyTwitter
* @param {object} req
* @param {object} res
*/
const verifyTwitter = (req, res) => {
var params = {user_id: req.user.firebase.identities['twitter.com'][0]}
TwitterClient.get('users/lookup', params, function (error, user, response) {
if (!error) {
const twitterProfile = user[0]
uportCredentials.receive(req.body.JWT)
.then(profile => {
uportCredentials.attest({
sub: profile.address,
claim: {
verifcationTwitter: {
name: twitterProfile.name,
screenName: twitterProfile.screen_name,
url: twitterProfile.url,
followers: twitterProfile.followers_count,
friends: twitterProfile.friends_count,
verified: twitterProfile.verified ? twitterProfile.verified : false
}
}
})
.then(attestation => {
const url = `me.uport:add?attestations=${attestation}`
uportCredentials.push(profile.pushToken, profile.publicEncKey, {url}).then(response => {
database.databaseWrite({
writeType: 'push',
branch: ['request', 'verification'],
payload: {
...response
}
})
})
}).catch(err => {
database.databaseWrite({
writeType: 'update',
branch: ['request', 'verifcation', 'error'],
payload: {
...err
}
})
})
})
} else {
console.log(error)
}
})
database.databaseWrite({
writeType: 'push',
branch: ['request', 'verify'],
payload: {
data: req.user,
meta: {
status: 'verified',
category: 'twitter',
type: 'verify'
}
}
})
res.json({user: req.user}).send()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment