django-allauth socialaccount not logging in? - django

I've recently switched server/database and am having trouble getting the google and facebook social apps to log in. I have the keys set up correctly and when hitting both facebook and google it successfully creates a django user and a social account, but it does not log the user in. Notably, it sends the user to LOGIN_REDIRECT_URL correctly.
When attempting to sign in with an existing user after it has already been created, it also does not log in, but also sends to LOGIN_REDIRECT_URL correctly.
I can't figure out why it is behaving this way in the new environment, and am struggling on finding where to look. My best guess is that somewhere the pre_social_login signal or the social_account_added signal? Any ideas?
EDIT:
Also worth noting, I switched from python 3.4 to python 2.7, but django remained 1.6.5

Turned out I was missing the allauth.account.auth_backends.AuthenticationBackend in the settings AUTHENTICATION_BACKENDS when i did the migrate.

Related

How i can solve the CSRF Fobidden(403) django rest framework?

i'm working my project with django restframework, all is right except when i try to update a table, always appears the CSRF.
How i can set CSRF cookie?
Thanks
Screenshot
I experienced this earlier today while switching development projects and added to an existing thread here: Django CSRF Cookie Not Set
After checking the order of installed apps and middleware against the startproject template, clearing my browser cache resolved the issue.

Flask Login Sessions Not Working

I'm having an issue with Flask-Login where for some reason it seems to clear the data from my session. This issue only seem to happen to me when I run my application on AWS within a Docker container. There doesn't seem to be any issues when this is run locally within a Docker container. The container kick starts the application using supervisord to launch the nginx and gunicorn servers.
I'm using Flask-Login and SQLAlchemy to handle my user logins. I'm creating a custom token using the get_auth_token() method in my User model which stores the token with some session data in my database. I use the token_loader and user_loader callbacks to retrieve my User data from the database which works fine.
However, if I'm not actively using my application for a few minutes the session data seems to disappear when I change to a page that requires a login. My session cookie remains unchanged and my token_loader or user_loader callbacks never seem to be called. To work out what might be happening with the session I attached a #app.before_request handler to print the session contents:
[2015-09-29 14:47:21,348] DEBUG in __init__: <SecureCookieSession {u'csrf_token': '51b5b253c55ac954c1bc61dd2dca513e18c4d790', u'_fresh': True, u'user_id': 3, u'_id': 'd3adbd2ed3905986d515aeb04cd1ff7d'}>
[2015-09-29 14:47:21,382] DEBUG in __init__: <SecureCookieSession {u'_flashes': [('message', u'Please log in to access this page.')]}>
It appeared that all of the user information was there for me to be able to load my user but it has bailed out and re-directed to the login page with the Flask-Login flash error. This re-directs before it even touches my callbacks to load the user from the database.
Is this possibly just a set up issue with my server configs that is causing an issue with domains? I'm not really sure what I need to look at and try to debug this further.
This is a known bug in Flask-Login that was fixed around release 0.2.10 (by me). The bug reappeared in release 0.3.0 of Flask-Login, which as of today is the most current release. I submitted a new fix, plus a unit test to prevent this from ever happening again. The fix was merged a few days ago, but a 0.3.1 release has not been made yet.
Bug report: https://github.com/maxcountryman/flask-login/issues/231
My pull request with the fix: https://github.com/maxcountryman/flask-login/pull/237

Django authentication works on Chrome, but not on Firefox

I'm having a problem where Django's login is working okay on Chrome but not on Firefox: when trying to login to a restricted portion of the site on Firefox, it simply loops back again and again to the login page; furthermore, no error message appears on the log regarding that.
Interestingly, the error doesn't happen when the server is on the local machine.
Does someone have a general idea of what could be causing that strange behavior?
I'm using Django 1.6 on Python 2.7
this isn't much of an answer, but a linking to other similar problems. Because I don't have rep, all I can do is leave an answer.
A issue like this was encountered in 2012 but was never conclusively answered:
Django session doesn't work in Firefox
A similar question where the user could login via local server but not remote firefox was encoutered:
Unable log in to the django admin page with a valid username and password
The second was very well documented and had an accepted answer that was well liked.
Recommendations:
If you are not using https make sure you have this setting SESSION_COOKIE_SECURE = False.
If you are using a database backed, Check if the session is actually being created in the django_sessions table .
If you are using a cached backed, check that SESSION_ENGINE is django.contrib.sessions.backends.cache and that CACHE_BACKEND is properly configured.

django-allauth and twitter integration - Social Network Login Failure

I am trying to work with django-allauth. I followed the instructions at github page and done following:
Added allauth urls into urls.py
urlpatterns += patterns ('',
url('^accounts/', include('allauth.urls')),
url('^accounts/profile/$', ProfileView.as_view(), name='ProfileView'),
url('^login/$', login, name='account_login'),
url('^logout/$', logout, name='account_logout'),
url('^login/cancelled/$', login_cancelled, name='socialaccount_login_cancelled'),
url('^login/error/$', login_error, name='socialaccount_login_error'),
)
Updated TEMPLATE_CONTEXT_DIRS, TEMPLATE_CONTEXT_PROCESSORS, AUTHENTICATION_BACKENDS and INSTALLED_APPS. Also added ACCOUNT_AUTHENTICATION_METHOD = "username_email"
Added Key and Secret for twitter in the Social apps table.
Copied django-allauth templates to my app's directory and modified it. I can see all the templates working fine like /accounts/signup/ and /accounts/social/connections/.
Now, from connections or signup when I click Twitter link /accounts/twitter/login/ I ended up with the following error:
Social Network Login Failure
An error occured while attempting to login via your social network
account.
Am I missing something? May be some stupid mistake (Twitter login url? No clues!). I also tried to find some tutorials based on the latest codebase but unable to find any. django-allauth example on github wasn't of any help. Please help. Also, please feel free to provide me any links or tutorials based on the latest codebase.
Thanks in advance.
I am a beginner so you can expect some stupid mistakes from people like me but I try to learn. I spent many hours trying to resolve this. Finally the issue turns out to be Twitter App Key Settings:
I get "Social Network Login Failure" error because my Twitter App settings are not configured for the localhost. Make sure you have the following settings configured in your Twitter App for your localhost (development machine):
Callback URL: http://127.0.0.1:8000/
NOTE: If you want to use it for production server then you need to set Callback to your domain name as follows:
Callback URL: http://Your_Domain_Name.com
OR better use another set of Keys specifically for production use only.
BONUS : If you are using django-social-auth and you don't have these settings configured then you may end up with 401 Unauthorized error.

Invite Only app for Django Auth

I'm working on a Django web app and want to restrict signup to my site. For thatI want to use invite only app..I could find a couple of app built on the top of Django registration but I'm using Django Auth . Is there any app which I can use with Django app to get the same functionality.
General idea:
First, you can check out the code I have written which works fine for me.
Take a look at the example include in the application, you will learn
how to write your own pipeline. this pipeline can be redirected to any
view you would like.
from there you can save a invitation_key in your sessions and if that
key is valid, you can continue with create_user built in pipeline.
I have used this application for invitations that produces and validates invitation keys.
Implementation
It took me quite a day to figure it out.
This is a invite app built on allauth which restricts signup to invite only:
https://pypi.python.org/pypi/django-invitations/0.12