Can't remove headers oAuth
Ravichandrane opened this issue · comments
Ravi Rajendran commented
Hi Simon,
I have another problem with Purest for a project in Koa, I use grant-koa to get the user access token and try to use purest to get more informations about the user but on my console I get : Can't remove headers after they are sent.
Do you have an idea ?
Many thanks,
Cheers.
const request = require('request');
const promise = require('bluebird');
const purest = require('purest')({request, promise});
const config = require('@purest/providers');
const facebook = purest({provider: 'facebook', config});
function* facebook(next) {
const self = this;
const access_token = self.query.access_token;
const references =['id','first_name','last_name','email','birthday','gender','timezone','locale','location'];
facebook
.get('me?fields='+ references.join(','))
.auth(access_token)
.request(function (err, res, body) {
self.body = body;
})
}
Ravi Rajendran commented
Finally I found a solution but I don't know if it's correct :
function* facebook() {
const self = this;
const profile = yield getFacebookProfile(self.query.access_token);
self.body = profile;
}
function getFacebookProfile (access_token) {
const references = ['id','first_name','last_name','email','birthday','gender','timezone','locale','location'];
return new Promise( (resolve, reject) => {
const req = facebook
.get('me?fields='+ references.join(','))
.auth(access_token)
.request();
req
.then((results) => {
resolve(results[1]);
})
.catch((err) => {
return reject(err);
});
})
simo commented
Yep, this is the correct way to do it.
Ravi Rajendran commented
Oh cool thanks @simov :)