Last active
July 19, 2021 21:49
-
-
Save FMFigueroa/d99913f5aca9a9ecdc7a834e32aec614 to your computer and use it in GitHub Desktop.
Authenticator_Facebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#agregar en requirements.txt | |
social-auth-app-django | |
#agregar a installed_apps | |
'social_django', | |
#en el archivo principal de urls | |
path('social-auth/', include('social_django.urls', namespace="social")), | |
#tokens | |
SOCIAL_AUTH_FACEBOOK_KEY = "key" | |
SOCIAL_AUTH_FACEBOOK_SECRET = "secret" | |
#agregar al final del settings.py | |
AUTHENTICATION_BACKENDS = [ | |
'social_core.backends.facebook.FacebookOAuth2', | |
'django.contrib.auth.backends.ModelBackend', | |
] | |
#enlace para login.html | |
<a href="{% url 'social:begin' 'facebook' %}">Ingresar con facebook</a> | |
#agregar a context_proccessors | |
'social_django.context_processors.backends', | |
'social_django.context_processors.login_redirect', | |
#MIDDLEWARE | |
'social_django.middleware.SocialAuthExceptionMiddleware', | |
#obtener campos adicionales desde facebook | |
#con esta configuracion podemos traer el email y la imagen | |
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email', 'user_link'] | |
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = { | |
'fields': 'id, name, email, picture.type(large), link' | |
} | |
SOCIAL_AUTH_FACEBOOK_EXTRA_DATA = [ | |
('name', 'name'), | |
('email', 'email'), | |
('picture', 'picture'), | |
('link', 'profile_url'), | |
] | |
#para agregar la imagen en base.html agregar: | |
{% for auth in backends.associated %} | |
{% if auth.provider == 'facebook' %} | |
<img src="{{ auth.extra_data.picture.data.url }}" alt="" width="50" height="50"> | |
{% endif %} | |
{% endfor %} | |
#excepciones | |
SOCIAL_AUTH_RAISE_EXCEPTIONS = False | |
LOGIN_ERROR_URL = '/error-facebook/' | |
#agregar a middleware | |
'social_django.middleware.SocialAuthExceptionMiddleware', | |
# Enjoy it..! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment