A tutorial for setting up a basic passport example.
LoopBack example for loopback-passport module. It demonstrates how to use LoopBack's user/userIdentity/userCredential models and passport to interact with other auth providers.
Before starting this tutorial, make sure you have the following installed:
$ git clone git@github.com:strongloop/loopback-example-passport.git
$ cd loopback-example-passport
$ npm install
localhost:[port#]
as your "Site URL".Update providers.json with your own values for clientID/clientSecret
.
"facebook-login": {
"provider": "facebook",
"module": "passport-facebook",
"clientID": "xxxxxxxxxxxxxxx",
"clientSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"callbackURL": "/auth/facebook/callback",
"authPath": "/auth/facebook",
"callbackPath": "/auth/facebook/callback",
"successRedirect": "/auth/account",
"failureRedirect": "/login",
"scope": ["email"],
"failureFlash": true
},
"facebook-link": {
"provider": "facebook",
"module": "passport-facebook",
"clientID": "xxxxxxxxxxxxxxx",
"clientSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"callbackURL": "/link/facebook/callback",
"authPath": "/link/facebook",
"callbackPath": "/link/facebook/callback",
"successRedirect": "/auth/account",
"failureRedirect": "/login",
"scope": ["email", "user_likes"],
"link": true,
"failureFlash": true
}
In a recent update, Facebook no longer returns all fields by default (email, gender, timezone, etc). If you need more information, modify the providers template.
The current template contains:
"profileFields": ["gender", "link", "locale", "name", "timezone", "verified", "email", "updated_time"],
We recommend modifying the fields to suit your needs. For more information regarding the providers template, see http://loopback.io/doc/en/lb2/Configuring-providers.json.html.
server\datasources.json
, add:"file":"db.json"
after
"connector": "memory",
$ node .
http://localhost:3000
Clone the application as describe above.
profileAttributesFromLDAP
and server
section "ldap": {
"provider": "ldap",
"authScheme":"ldap",
"module": "passport-ldapauth",
"authPath": "/auth/ldap",
"successRedirect": "/auth/account",
"failureRedirect": "/ldap",
"session": true,
"failureFlash": true,
"profileAttributesFromLDAP": {
"login": "uid",
"username": "uid",
"displayName": "displayName",
"email": "mail",
"externalId": "uid"
},
"server":{
"url": "ldap://ldap-server:1234",
"searchBase": "dc=domain,dc=fr",
"searchFilter": "(cn={{username}})"
}
},
Here, in profileAttributesFromLDAP
section, we have configured the mapping to get
login
, username
and extranalId
from LDAP's uid
,displayName
from LDAP's displayName
email
from LDAP's mail
$ node .
http://localhost:3000