Facebook login can be initialized like any other OAuth provider by adding the app id and secret to config/default.json
:
{
"authentication": {
"oauth": {
"facebook": {
"key": "<App ID>",
"secret": "<App Secret>"
}
}
}
}
Requesting the email property requires adding additional scope
to the oauth configuration:
{
"authentication": {
"oauth": {
"facebook": {
"key": "<App ID>",
"secret": "<App Secret>",
"scope": ["email, public_profile"]
}
}
}
}
# Application client and secret
The client id (App ID) and secret can be found in the Settings of the Facebook app (opens new window):
# Getting profile data
The standard OAuth strategy only returns the default profile fields (id
and name
). To get other fields, like the email or profile picture, the getProfile method of the OAuth strategy needs to be customized to call the Graph API profile endpoint https://graph.facebook.com/me
with an HTTP request library like Axios (opens new window) requesting the additional fields.
Pro tip: Facebook API requests can be tested via the Graph API explorer (opens new window).
The following example allows to log in with Facebook in the chat application from the guide:
Pro tip: See all available Facebook user options here (opens new window).