I've been stuck in this issue for two days now and nothing. I successfully setup Google sign in and it works. Every time I try with facebook, I get the following error:
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'profile',
'email',
],
'AUTH_PARAMS': {
'access_type': 'online',
}
}
}
\
{
'facebook': {
'METHOD': 'oauth2',
# 'SDK_URL': '//connect.facebook.net/{locale}/sdk.js',
'SCOPE': ['email', 'public_profile'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'INIT_PARAMS': {'cookie': True},
'FIELDS': [
'id',
"email"
'first_name',
'last_name',
'middle_name',
'name',
'name_format',
'picture',
'short_name'
],
'EXCHANGE_TOKEN': True,
'LOCALE_FUNC': 'path.to.callable',
'VERIFIED_EMAIL': False,
'VERSION': 'v13.0',
'GRAPH_API_URL': 'https://graph.facebook.com/v13.0',
}
}
ACCOUNT_DEFAULT_HTTP_PROTOCOL="https"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'email'
Client ID and secret has been added in admin. If i remove the http method allowed, I get a different error mentioning "You can't get an access token or login to this app from an insecure page. Try re-loading the page as https://"
Any help would be appreciated. Thanks!
Related
my backend in laravel and i set if user login to another device then current device auth token is invalid
i also want if he get unathenticated error 401 in axios then instant logout and redirect to login page
i am doing like this
export default function({ $axios, redirect, $auth }) {
$axios.onError(error => {
if (error.response.status === 401) {
if ($auth.loggedIn) {
$auth.logout();
}
redirect("/login");
}
});
}
but nothing happen and when i check console.log($auth) its getting undefine
Help me thank you
If you need to access $auth from $axios plugin, you can use auth.plugins option.
https://auth.nuxtjs.org/recipes/extend.html
{
modules: [
'#nuxtjs/auth'
],
auth: {
plugins: [ { src: '~/plugins/axios', ssr: true }, '~/plugins/auth.js' ]
}
}
I've created an app and deployed it live on digitalocean and enabled HTTPS with certbot, when I want to login with facebook:
I got this error:
and the redirect URL:
is not HTTPS:
My code:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'social_django',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
]
SOCIALACCOUNT_PROVIDERS = {
'facebook': {
'METHOD': 'oauth2',
'SCOPE': ['email', 'public_profile'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'INIT_PARAMS': {'cookie': True},
'FIELDS': [
'id',
'email',
'name',
'first_name',
'last_name',
'verified',
'locale',
'timezone',
'link',
'gender',
'updated_time',
],
'EXCHANGE_TOKEN': True,
'LOCALE_FUNC': 'path.to.callable',
'VERIFIED_EMAIL': False,
'VERSION': 'v2.12',
}
}
SOCIAL_AUTH_REDIRECT_IS_HTTPS = True
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
# 'social_core.backends.facebook.FacebookOAuth2',
'allauth.account.auth_backends.AuthenticationBackend',
)
login btn
{% load socialaccount %}
Facebook OAuth2
Try adding the following to your settings:
ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https'
(see this issue on the allauth github https://github.com/pennersr/django-allauth/issues/1994)
This is my function that I get the profile info of user:
function facebookLogin() {
return $q(function(resolve, reject) {
$cordovaOauth.facebook('CLIENT_ID', ['id', 'email', 'name', 'age_range', 'gender', 'user_photos', 'user_work_history', 'user_friends']).then(function(result) {
$localStorage.facebookToken = result.access_token
$http.get('https://graph.facebook.com/v2.8/me', { params: { access_token: $localStorage.accessToken, fields: 'id, name, email, gender, picture', format: "json" } }).then(function(profile) {
alert(JSON.stringify(profile.data))
resolve(true)
}, function(err) {
console.log(err)
})
}, function(err) {
alert('Erro login: ' + JSON.stringify(err))
})
})
}
In the first function facebook, facebook renders a window and then the user logs in, but I always get this screen, it says: 'Something went wrong, We're working to fix this as soon as possible':
If I i quit this window then the catch error is called and I get "The sign flow was canceled", any ideas?
It was a problem with permissions when i call facebook screen
I have a meteor app, with packages :
useraccounts:bootstrap;
service-configuration;
accounts-facebook;
The facebook side was configured to allow requests from localhost. When using the register/signin with facebook from the atForm, a popup appears
EDIT
The popup is actually not empty but displays a message 'login complete, click to close' but closed fast because that's how I configured it on the facebook side.
And the console logs an error:
Exception while invoking method 'login' undefined
EDIT
Here is the service conf:
ServiceConfiguration.configurations.remove({
service: 'facebook'
});
ServiceConfiguration.configurations.insert({
service: 'facebook',
appId: 'removed',
secret: 'removed'
});
EDIT
Here is the client side code :
Template.atForm.events({
'click #at-facebook': function(event) {
console.log("facebook click");
Meteor.loginWithFacebook({
requestPermissions: ['email', 'user_friends']
}, function (err) {
if (err)
Session.set('errorMessage', err.reason || 'Unknown error');
});
}
});
EDIT
When registering with facebook the user created is as follow :
{ createdAt: Thu Jan 21 2016 16:00:08 GMT+0100 (CET),
I20160121-16:00:08.108(1)? _id: 'Kgs3WswMdB9hsxMfp',
I20160121-16:00:08.108(1)? services:
I20160121-16:00:08.108(1)? { facebook:
I20160121-16:00:08.108(1)? { accessToken: 'removed',
I20160121-16:00:08.108(1)? expiresAt: 1458562023670,
I20160121-16:00:08.109(1)? id: 'removed',
I20160121-16:00:08.109(1)? email: 'removed',
I20160121-16:00:08.109(1)? name: 'Mathieu Kudla',
I20160121-16:00:08.109(1)? first_name: 'Mathieu',
I20160121-16:00:08.110(1)? last_name: 'Kudla',
I20160121-16:00:08.110(1)? link: 'https://www.facebook.com/app_scoped_user_id/removed/',
I20160121-16:00:08.110(1)? gender: 'male',
I20160121-16:00:08.110(1)? locale: 'fr_FR',
I20160121-16:00:08.110(1)? age_range: [Object] } } }
This seems to indicate that the facebook handshake was successful?
What is causing that error? Thanks :)
Ok I kinda solved it.
I digged in the log-in attempts and noticed that the oauth service was not properly paired with the user. I don't know why that is or if there is a better solve but I added the line :
if (user.services) { var service = _.pairs(user.services)[0]; }
to my onCreateUser hook and appended the user object properly before returning it. It seems to have done the trick but I don't know what I was not doing properly the first time...
I am using Meanjs.org boilerplate and Facebook Signup returns me to the Signup page.
Following are the steps that I have taken so far.
1) Setting up the Facebook App Site URL
http://localhost:3000/
and the callback URI of OAuth
http://localhost:3000/auth/facebook/callback
2) Placing the APP_ID and APP_Secret in as Client_ID and Client_Secret
facebook: {
clientID: process.env.FACEBOOK_ID || '*****',
clientSecret: process.env.FACEBOOK_SECRET || '*****',
callbackURL: 'http://localhost:3000/auth/facebook/callback',
profileFields: ['id','emails', 'first_name', 'last_name', 'displayName', 'link', 'about_me', 'photos' ]
},
3) Code is as follows
--Routes
// Setting the facebook oauth routes
app.route('/auth/facebook').get(passport.authenticate('facebook', {
scope: ['email']
}));
app.route('/auth/facebook/callback').get(users.oauthCallback('facebook'));
-- The oauthCallback function,
exports.oauthCallback = function(strategy) {
return function(req, res, next) {
passport.authenticate(strategy, function(err, user, redirectURL) {
if (err || !user) {
console.log('1' + err);
//console.log(user);
return res.redirect('/#!/signin');
}
req.login(user, function(err) {
if (err) {
console.log('2' + err);
return res.redirect('/#!/signin');
}
return res.redirect(redirectURL || '/');
});
})(req, res, next);
};
};
-- Passport-Facebook Strategy
module.exports = function() {
// Use facebook strategy
passport.use(new FacebookStrategy({
clientID: config.facebook.clientID,
clientSecret: config.facebook.clientSecret,
callbackURL: config.facebook.callbackURL,
passReqToCallback: true
},
function(req, accessToken, refreshToken, profile, done) {
console.log('facebook Strategy Started');
// Set the provider data and include tokens
var providerData = profile._json;
providerData.accessToken = accessToken;
providerData.refreshToken = refreshToken;
// console.log(JSON.stringify(profile));
console.log(profile);
// console.log(JSON.stringify(profile.name.givenName));
// Create the user OAuth profile
var providerUserProfile = {
firstName: profile.name.givenName,
lastName: profile.name.familyName,
displayName: profile.displayName,
email: profile.emails[0].value,
username: profile.username,
provider: 'facebook',
providerIdentifierField: 'id',
providerData: providerData
};
//console.log('provider' + providerUserProfile);
// Save the user OAuth profile
users.saveOAuthUserProfile(req, providerUserProfile, done);
}
));
};
4) Debugging
Logging err under oauthCallback function returns the following,
1TypeError: Cannot read property '0' of undefined
What Facebook returns as profile in Passport-Facebook module is as follows,
{ id: 'Id_of_the_person',
username: undefined,
displayName: 'Full_name_of_person',
name:
{ familyName: undefined,
givenName: undefined,
middleName: undefined },
gender: undefined,
profileUrl: undefined,
provider: 'facebook',
_raw: '{"name":"Full_name_of_person","id":"Id_of_the_person"}',
_json:
{ name: 'Id_of_the_person',
id: 'Id_of_the_person',
accessToken: 'access_token_value',
refreshToken: undefined } }
Can anyone be kind to guide me about getting the correct user profile from Facebook including user email?
Thank you so much.
I have my profile fields set to the following
profileFields: ['email','id', 'first_name', 'gender', 'last_name', 'picture']
Even though you set email it might return emails if the user has multiple emails. So you need to check if email was returned profile.email or profile.emails[0].value. You must also check if it is undefined, because there is people that register with facebook that never verify their email account and there is people that sign up with a phone number, in both those cases their emails will always be undefined.
you want to check that any required fields have values.
var email = profile.email || profile.emails[0].value;
if (! email){
console.log('this user has no email in his FB');
var err = {message:'this user is missing an email'};
return done(err);
}
now i can do this if they have an email
newUser.facebook.email = email;
if they don't have an email you can set a session for profile and send them to a page that asks them to enter an email.
It sounds like a pain, but you can never trust information from a third party api to have values.
Most of the passport examples I've seen online are wrong. They all assume an email is present.
First, profileFields field does not obey to Portable Contacts convention - and you can find the convention for passportjs here.
Second, in your example, after removing removed 'about_me', the Facebook signup returns no error. Before removing 'about_me', I had a different error: Tried accessing nonexisting field (about_me) on node type (User)
If the error persist, see this serie of 5 tutorials which helps me when I was doing the sign up page to authenticate with social networks accounts.