| 1 |
Facebook |
| 2 |
-------- |
| 3 |
|
| 4 |
For Facebook both OAuth2, Facebook Connect Javascript SDK and even |
| 5 |
`Limited Login <https://developers.facebook.com/docs/facebook-login/limited-login>`_ |
| 6 |
are supported. You can even mix and match. |
| 7 |
|
| 8 |
An advantage of the Javascript SDK may be a more streamlined user |
| 9 |
experience as you do not leave your site. Furthermore, you do not need |
| 10 |
to worry about tailoring the login dialog depending on whether or not |
| 11 |
you are using a mobile device. Yet, relying on Javascript may not be |
| 12 |
everybody's cup of tea. |
| 13 |
|
| 14 |
To initiate a login use: |
| 15 |
|
| 16 |
.. code-block:: python |
| 17 |
|
| 18 |
{% load socialaccount %} |
| 19 |
{% providers_media_js %} |
| 20 |
<a href="{% provider_login_url "facebook" %}">Facebook Connect</a> |
| 21 |
|
| 22 |
The following Facebook settings are available: |
| 23 |
|
| 24 |
.. code-block:: python |
| 25 |
|
| 26 |
SOCIALACCOUNT_PROVIDERS = { |
| 27 |
'facebook': { |
| 28 |
'METHOD': 'oauth2', # Set to 'js_sdk' to use the Facebook connect SDK |
| 29 |
'SDK_URL': '//connect.facebook.net/{locale}/sdk.js', |
| 30 |
'SCOPE': ['email', 'public_profile'], |
| 31 |
'AUTH_PARAMS': {'auth_type': 'reauthenticate'}, |
| 32 |
'INIT_PARAMS': {'cookie': True}, |
| 33 |
'FIELDS': [ |
| 34 |
'id', |
| 35 |
'first_name', |
| 36 |
'last_name', |
| 37 |
'middle_name', |
| 38 |
'name', |
| 39 |
'name_format', |
| 40 |
'picture', |
| 41 |
'short_name' |
| 42 |
], |
| 43 |
'EXCHANGE_TOKEN': True, |
| 44 |
'LOCALE_FUNC': 'path.to.callable', |
| 45 |
'VERIFIED_EMAIL': False, |
| 46 |
'VERSION': 'v13.0', |
| 47 |
'GRAPH_API_URL': 'https://graph.facebook.com/v13.0', |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
METHOD: |
| 52 |
Either ``js_sdk`` or ``oauth2``. The default is ``oauth2``. |
| 53 |
|
| 54 |
SDK_URL: |
| 55 |
If needed, use ``SDK_URL`` to override the default Facebook JavaScript SDK |
| 56 |
URL, ``//connect.facebook.net/{locale}/sdk.js``. This may be necessary, for |
| 57 |
example, when using the `Customer Chat Plugin <https://developers.facebook.com/docs/messenger-platform/discovery/customer-chat-plugin/sdk#install>`_. |
| 58 |
If the ``SDK_URL`` contains a ``{locale}`` format string named argument, |
| 59 |
the locale given by the ``LOCALE_FUNC`` will be used to generate the |
| 60 |
``SDK_URL``. |
| 61 |
|
| 62 |
SCOPE: |
| 63 |
By default, the ``email`` scope is required depending on whether or not |
| 64 |
``SOCIALACCOUNT_QUERY_EMAIL`` is enabled. |
| 65 |
Apps using permissions beyond ``email`` and ``public_profile`` |
| 66 |
require review by Facebook. |
| 67 |
See `Permissions with Facebook Login <https://developers.facebook.com/docs/facebook-login/permissions>`_ |
| 68 |
for more information. |
| 69 |
|
| 70 |
AUTH_PARAMS: |
| 71 |
Use ``AUTH_PARAMS`` to pass along other parameters to the ``FB.login`` |
| 72 |
JS SDK call. |
| 73 |
|
| 74 |
FIELDS: |
| 75 |
The fields to fetch from the Graph API ``/me/?fields=`` endpoint. |
| 76 |
For example, you could add the ``'friends'`` field in order to |
| 77 |
capture the user's friends that have also logged into your app using |
| 78 |
Facebook (requires ``'user_friends'`` scope). |
| 79 |
|
| 80 |
EXCHANGE_TOKEN: |
| 81 |
The JS SDK returns a short-lived token suitable for client-side use. Set |
| 82 |
``EXCHANGE_TOKEN = True`` to make a server-side request to upgrade to a |
| 83 |
long-lived token before storing in the ``SocialToken`` record. See |
| 84 |
`Expiration and Extending Tokens <https://developers.facebook.com/docs/facebook-login/access-tokens#extending>`_. |
| 85 |
|
| 86 |
LOCALE_FUNC: |
| 87 |
The locale for the JS SDK is chosen based on the current active language of |
| 88 |
the request, taking a best guess. This can be customized using the |
| 89 |
``LOCALE_FUNC`` setting, which takes either a callable or a path to a callable. |
| 90 |
This callable must take exactly one argument, the request, and return `a |
| 91 |
valid Facebook locale <http://developers.facebook.com/docs/ |
| 92 |
internationalization/>`_ as a string, e.g. US English: |
| 93 |
|
| 94 |
.. code-block:: python |
| 95 |
|
| 96 |
SOCIALACCOUNT_PROVIDERS = { |
| 97 |
'facebook': { |
| 98 |
'LOCALE_FUNC': lambda request: 'en_US' |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
VERIFIED_EMAIL: |
| 103 |
It is not clear from the Facebook documentation whether or not the fact |
| 104 |
that the account is verified implies that the email address is verified |
| 105 |
as well. For example, verification could also be done by phone or credit |
| 106 |
card. To be on the safe side, the default is to treat email addresses |
| 107 |
from Facebook as unverified. But, if you feel that is too paranoid, then |
| 108 |
use this setting to mark them as verified. Due to lack of an official |
| 109 |
statement from the side of Facebook, attempts have been made to |
| 110 |
`reverse engineer the meaning of the verified flag <https://stackoverflow.com/questions/14280535/is-it-possible-to-check-if-an-email-is-confirmed-on-facebook>`_. |
| 111 |
Do know that by setting this to ``True`` you may be introducing a security |
| 112 |
risk. |
| 113 |
|
| 114 |
VERSION: |
| 115 |
The Facebook Graph API version to use. The default is ``v13.0``. |
| 116 |
|
| 117 |
App registration (get your key and secret here) |
| 118 |
A key and secret key can be obtained by |
| 119 |
`creating an app <https://developers.facebook.com/apps>`_. |
| 120 |
After registration you will need to make it available to the public. |
| 121 |
In order to do that your app first has to be |
| 122 |
`reviewed by Facebook <https://developers.facebook.com/docs/apps/review>`_. |
| 123 |
|
| 124 |
Development callback URL |
| 125 |
Leave your App Domains empty and put ``http://localhost:8000`` in the |
| 126 |
section labeled ``Website with Facebook Login``. Note that you'll need to |
| 127 |
add your site's actual domain to this section once it goes live. |
| 128 |
|
| 129 |
For Limited Login, it is exclusively supported via the Headless API's "provider |
| 130 |
token" flow. |
| 131 |
|
| 132 |
Pass your Limited Login JWT (obtained from the Facebook iOS SDK) to that |
| 133 |
endpoint as an ``id_token``. |
| 134 |
|
| 135 |
Note that Limited Login is purely used for login and does not allow access to |
| 136 |
the user's Facebook account - no ``SocialToken`` is created. |