Для социального входа в систему в LoopBack + mobileApp .
Я добавил пример для loopback + ionicApp.
1. Вам нужно добавить Facebook SDK в ваше приложение.
2. Добавить facebookLogin в приложение
Пример:
this.fb
.login(["public_profile", "user_friends", "email"])
.then(res => {
var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/json' );
const requestOptions = new RequestOptions({ headers: headers });
var provider = 'facebook';
var authSchema = 'oAuth 2.0';
// Make a request to google api
// to exchange refreshToken and accessToken with using google apis
var accessToken = 'FROM FACEBOOK API';
var refreshToken = 'FROM FACEBOOK API';
// external id is your google or facebook user id
var externalId = 'FROM FACEBOOK API';
var email = 'FROM FACEBOOK API';
var credentials = {};
credentials.externalId = externalId;
credentials.refreshToken = refreshToken;
var profile = {};
profile.id = externalId;
profile.emails = [{type:'account', value: email}];
let postData = {
provider,
authSchema,
profile,
credentials
}
this.http.post("http://you-api-url/socail-login", postData, requestOptions)
.subscribe(data => {
console.log(data); //here you get token set in localhost as current login done.
}, error => {
console.log(error);
});
})
.catch(e => console.log("Error logging into Facebook", e));
Здесь создайте почтовый запрос в шлейфе для входа в систему
module.exports = function(app, router) {
const UserIdentityModel = app.models.UserIdentity;
const EndUser = app.models.EndUser;
/*Api for third party */
router.post('/social-login', function(req, res) {
if (!req.body.provider || !req.body.authSchema || !req.body.profile || !req.body.credentials) {
res.status(501).send({ error: 'Something went wrong' });
return;
}
UserIdentityModel.login(
req.body.provider, req.body.authSchema, req.body.profile, req.body.credentials, { autoLogin: true }, ipAddress,
function(err, loopbackUser, identity, token) {
if (err) {
res.status(501).send({ error: 'Something went wrong' });
return;
}
// token is access token for thig login
res.json({ loopbackUser: loopbackUser, identity: identity, token: token });
//return res.send(token);
});
});
};