How to get friend list from Google Plus by using Passport - passport.js

I can get Facebook friends list with Passport:
new FacebookStrategy({
// pull in our app id and secret from our auth.js file
clientID : config.facebook.clientID,
clientSecret : config.facebook.clientSecret,
callbackURL : config.facebook.callbackURL,
profileFields : ["id", "birthday", "email", "first_name", "friends", "last_name"]
}
I am curious whether there is a way for Google Plus in the similar fashion?
new GoogleplusStrategy({
clientID : configAuth.googleAuth.clientID,
clientSecret : configAuth.googleAuth.clientSecret,
callbackURL : configAuth.googleAuth.callbackURL
}
I am using "passport-google-oauth" module for the strategy.
Thanks
Derek

An indirect way is :
GET www.googleapis.com/plus/v1/people/userid/people/connected?access_token=accessToken
Using querystring or https can do the work.

Related

Is there a way to madatorily ask facebook profiles for email using passport.js?

I'm using passport-facebook for authentication in my node.js app, using the following strategy:
passport.use(new FacebookStrategy({
clientID : '...',
clientSecret : '...',
callbackURL : '/auth/facebook/callback',
profileFields: ['id', 'emails', 'name', 'gender']
},
function(accessToken, refreshToken, profile, done) {
process.nextTick(function () {
console.log(profile.email);
...
This should be enough to get the id, emails, name and gender from the user's profile, but there's a way in which an user could
untick the option to share his emails , in that case the value of the email attribute in the profile object returned by Graph API is 'undefined'.
I'd like to require that data to be shared with my app, is there a way to mandatorily ask Facebook profiles for emails using passport.js?

Using strategy passport paypal : failed to obtain access token

With Passport (by Jared Hanson),
How can I use Paypal with openID or OAuth ?
I'm using passport-paypal-oauth strategy (https://github.com/jaredhanson/passport-paypal-oauth),
NOTE : my routes start with localhost:4000/api/users
http://localhost:4000/api/users/signin/paypal
http://localhost:4000/api/users/signin/paypal/callback
My paypal endpoints :
var passport_paypal = require('../middlewares/passport-paypal');
router.get('/signin/paypal', passport_paypal.authenticate('paypal-signin', {
scope: 'openid profile email'}));
router.get('/signin/paypal/callback', function(req, res, next){
passport_paypal.authenticate('paypal-signin', function(err, user, info){
// Handle cases
//return res.status(xxx).json('..
});
My Paypal Strategies :
var PaypalStrategy = require('passport-paypal-oauth').Strategy;
passport.use('paypal-signin', new PaypalStrategy({
clientID : "MY APP ID",
clientSecret : "MY APP SECRET",
callbackURL : "http://localhost:4000/api/users/signin/paypal/callback",
tokenURL : "https://api.sandbox.paypal.com/v1/oauth2/token",
authorizationURL : "https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize"
}, function(token, refreshToken, profile, done) {
!!!!! Not called ...
// Get user profie
// Save in db or other handling
}));
Problem : When I call http://localhost:4000/api/users/signin/paypal,
I get the following answer in the browser :
[InternalOAuthError: failed to obtain access token]
name: 'InternalOAuthError',
message: 'failed to obtain access token',
oauthError:
{ statusCode: 400,
data: '{"error":"invalid_client","error_description":"Client credentials are missing"}' } }
And the function(token, refreshToken, profile, done) { is never called.
What is wrong ?
I've already tested with http://127.0.0.1:4000/api/users/signin/paypal
instead http://localhost:4000/api/users/signin/paypal
I am the one who forked and maintains the openid-connect package
the tokenURL should be the openidconnect url and not the oauth2 token url...
You can leave out the tokenURL and authorizationURL and just use sandbox: true (I can't speak for passport-paypal, I forgot if it has that built in too)
passport.use('paypal-signin', new PaypalStrategy({
clientID : "MY APP ID",
clientSecret : "MY APP SECRET",
callbackURL : "http://localhost:4000/api/users/signin/paypal/callback",
sandbox: true
}, function(token, refreshToken, profile, done) {
// Get user profie
// Save in db or other handling
done(true);
}));
I dont know if it will resolve the problem, but the done function should be called in the callback with a true value if ok.
passport.use('paypal-signin', new PaypalStrategy({
clientID : "MY APP ID",
clientSecret : "MY APP SECRET",
callbackURL : "http://localhost:4000/api/users/signin/paypal/callback",
tokenURL : "https://api.sandbox.paypal.com/v1/oauth2/token",
authorizationURL : "https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize"
}, function(token, refreshToken, profile, done) {
// Get user profie
// Save in db or other handling
done(true);
}));

Facebook-passport strategy not returning emails field

I am using Facebook v2.5 API.
route :
app.get('/auth/facebook', passport.authenticate('facebook', { scope : 'email' }));
config :
passport.use(new FacebookStrategy({
clientID: CLIENTID,
clientSecret: CLIENTSECRET,
callbackURL: callbackURL,
profileFields: ["emails", "displayName", "gender"]
},
function (token, refreshToken, profile, done) {
console.log(profile)
...
}));
profile does not have "emails" field.
I tried passing scope as an array too
scope : ['email']
I just had the same problem: using my test account and working with the scopes, I suddenly "lost" the email address, no way to get it again using all the hints found here.
Curiously using a new facebook account, the email address appeared.
=> I went to my test account in facebook and revoked all rights for my app there. Afterwards I logged into my app again and granted all the rights needed. Since then I receive the email address again.
Hope this helps.
Make sure you define "email" scope while login, then you could get it when you ask graph.facebook.com:
$url = 'https://www.facebook.com/dialog/oauth';
$params = array(
'client_id' => $this->strategy['app_id'],
'redirect_uri' => $this->strategy['redirect_uri'],
'scope' => 'email',
);

How can I Insert account my google glass using node.js

I'd like insert account my google glass, but I cann't do that.
I'm using node.js(v0.10.31), googleapis(v1.0.11) and passport-google-oauth(v0.1.5)
of course, I turned on Google Mirror API on Google Developers Console. and made pem file.
Here is google Developers console setting.
(I tried to upload pics but, I need some levels.)
pkginfo.oauth.google
CLIENT ID 670282105???-a???pbnh1pp.apps.googleusercontent.com
EMAIL ADDRESS 670282105???-????nh1pp#developer.gserviceaccount.com
CLIENT SECRET jt0WiP???pCwXT
REDIRECT URIS http://www.-----------.com:3333/auth/google/callback
JAVASCRIPT ORIGINS http://www.-----------.com:3333
http://www.-----------.com
https://mirror-api-playground.appspot.com
.
pkginfo.oauth.glass
CLIENT ID 67028????qjv.apps.googleusercontent.com
EMAIL ADDRESS 6702821053????qjv#developer.gserviceaccount.com
PUBLIC KEY
FINGERPRINTS e25e3a045????a4e40 – Delete
822e7bda????e85c56 – Delete
70ae6e7c????45c7c9 – Delete
Here are my codes.
passport.use(new GoogleStrategy({
clientID: pkginfo.oauth.google.CLIENT_ID,
clientSecret: pkginfo.oauth.google.CLIENT_SECRET,
callbackURL: pkginfo.oauth.google.REDIRECT_URL
},
function(accessToken, refreshToken, profile, done) {
var googleapis = require('googleapis');
var mirror = googleapis.mirror('v1');
var OAuth2 = googleapis.auth.OAuth2;
var jwt = new googleapis.auth.JWT(pkginfo.oauth.glass.EMAIL_ADDRESS,
pkginfo.oauth.glass.KEY_FILE,
null,//'notasecret',
['https://www.googleapis.com/auth/glass.thirdpartyauth'],
null);
jwt.authorize(function(err, tokens) {
if (err) clog.error("Error #jwt.authorize:" + err);
var oAuth2Client = new OAuth2(pkginfo.oauth.google.CLIENT_ID,
pkginfo.oauth.google.CLIENT_SECRET,
'postmessage');
oAuth2Client.setCredentials({
access_token : tokens.access_token
})
var params = {
auth: oAuth2Client,
userToken : accessToken,
accountType : "com.cocoa.glasshelpme",
accountName : profile.emails[0].value,
resource :
{
features: ["a", "b", "c"],
userData: [
{key : "realName" , value : "James jerry"}
],
authTokens: [
{ type: tokens.token_type, authToken: accessToken }
]
}
};
mirror.accounts.insert(params, callback);
function callback(err,result) {
clog.error(err);
clog.debug(result);
};
and I got this error message.
error: { errors: [ { domain: 'global', reason: 'invalid', message: 'Invalid Value' } ],
code: 400,
message: 'Invalid Value' }
Thank you.
Make sure you've reached out to the review team to upload your APK on MyGlass and provided them with the exact account type you are going to use (e.g com.cocoa.glasshelpme): those steps are required before you can start using this API.
You can find more information on the developers guide.
UPDATE: Just saw that you are using userToken parameter with an accessToken argument; the userToken should be the one that got provided by MyGlass when the user clicked on the auth URL.

Facebook OAuth2 does not provide user email

This has been asked many times but it seems like there's no known work-around for it so I'm posting this question in the hope that someone does have a work-around for it.
I'm using NodeJS, PassportJS-Facebook.
app.get("/auth/facebook",
passport.authenticate("facebook", {
scope : [ "email" ]
}),
function (req, res) {
});
At first I thought it's a PassportJS issue but I certainly eliminated this option.
The Facebook user account I'm using clearly states:
This app needs:
Your basic info
Your email address (xyz#example.com)
Some links to this known issue (yet unsolved!):
https://developers.facebook.com/bugs/298946933534016
https://developers.facebook.com/bugs/429653750464521
https://developers.facebook.com/bugs/482815835078469
So, do you use Facebook's OAuth service? If so, do you get the user's email? How? The "straight" way? A work-around?
The Facebook strategy in passportjs, expects a profileFields field in the options. Try passing "email" in the options.
strategyOptions.profileFields = ['emails', 'first_name', 'last_name'];
Alternatively, you can override the profileUrl in the options and send:
strategyOptions.profileURL = 'https://graph.facebook.com/me?fields=location,first_name,last_name,middle_name,name,link,username,work,education,gender,timezone,locale,verified,picture,about,address,age_range,bio,birthday,cover,currency,devices,email,favorite_athletes,id,hometown,favorite_teams,inspirational_people,install_type,installed,interested_in,languages,meeting_for,name_format,political,quotes,relationship_status,religion,significant_other,sports,updated_time,website';
Facebook will ignore fields that you don't have a permission to (like email).
This should go here:
passport.use(new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: "http://localhost:3000/auth/facebook/callback",
profileUrl: " ..... ",
//or
profileFields: [ ... ];
},
function(accessToken, refreshToken, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
// To keep the example simple, the user's Facebook profile is returned to
// represent the logged-in user. In a typical application, you would want
// to associate the Facebook account with a user record in your database,
// and return that user instead.
return done(null, profile);
});
}
));
```
You must provide field 'scope' in settings object:
new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: "http://localhost:3000/auth/facebook/callback",
profileUrl: " ..... ",
scope: "email",
//or
profileFields: [ ... ];
}
try to look sources.

Resources