No Facebook login screen in django social auth - django

I am trying to build a small page using django which uses a facebook login, and I am using the django-social-auth package from agiliq: https://github.com/agiliq/Django-Socialauth and trying to follow the documentation.
However, I am not able to see/test the login from facebook.
The settings.py and urls.py can be found here: http://dpaste.com/685141/
When I go to: 127.0.0.1:8000/login/facebook I get the following error from facebook:
f Error:
An error occurred. Please try later
where, f is the facebook sprite.
As I understand, I think I need to specify the redirect url (?) but I am not entirely sure how to go about doing this.

Don't confuse django-socialauth with django-social-auth, they try to solve the same but on quite different ways.

Well First of all I don't see the SOCIAL_AUTH_ENABLED_BACKENDS setting
mine is like this:
SOCIAL_AUTH_ENABLED_BACKENDS = ('twitter','facebook','google')
Also be advised that facebook will never return an ok state for a remote url that does not match the domain name you said you had in your app.
So localhost != domain name is not cool to them.
also I'd advise if you took down your dpaste because your keys, email and root password are exposed.

Related

How to return a 404 for just Django allauth signup page?

I am rather new to Django and all of the work I have done so far has been with models/views/viewsets.. The site I am working on incorporates Django allauth for authentication. I have successfully edited/styled the login/logout templates, but the page will be accessed by people who are given credentials created in the admin section rather than signing up on their own- so the sign up page is unnecessary. I'd like to just show a 404 page anytime someone lands on the signup page. I have already removed all the links to the signup page from the other templates.
In short- how do I just redirect someone to the Django default page_not_found when they hit /accounts/signup/?
My attempts so far have revolved around editing the URLs.py file to include something like path('account_signup', page_not_found) (after importing it at the top), or some other manipulation of that line. I'm probably missing something really easy, as I have been getting a little frustrated... And I haven't found any stack overflows where someone was desiring a 404 when a user navigated to one of the allauth account pages.
In order to server 404 pages automatically for not found url, create a 404 view and then in main projects urls.py have below code
Read the Official docs
handler404 = 'mysite.views.my_custom_page_not_found_view'
For redirecting use Redirect View in django docs
from django.views.generic.base import RedirectView
url('/accounts/signup/', RedirectView.as_view(url='/', permanent=False),name='index')
Note their is 404 page for developers builts in django, but once you turn debug=False in settings for production apps,it is not visible,
You can simply not use the signup page in your urls.
On the other hand, it is bad practice to use createsuperuser to create users, since by default they will have enough privileges, even to log in to admin and edit things. The right thing to do is to create a user with some method you want, and with the permissions you give them.
This last one will allow you to use a decorator in your signup view that only allows access to that page in case you have an account with a particular privilege, and not any user. There is no point in returning a 404.

How do I create a site where a registered user has a personal url for the site

I'm working on a project and I want to make it in such a way that each registered user has a personal url for the site. For example, a user named james, when logged in, the url will look like this: james.google.com. Just like the same format as wordpress
P.S I'm using django
I think what you're looking for is Django Subdomains. Have you looked into that package?

In django-allauth, how do I add the OpenId social app?

Just starting to learn django, and I wanted to incorporate the allauth app.
Been trying to figure this out all day and haven't found the answer in other questions.
Anytime I try to add one of the social logins, I can't even get a login screen and django complains:
get_login_url() keywords must be strings
when it tries to render the provider list. (I copied over base, index, and profile from the example that came with allauth)
I've read that before I use one of the logins, I need to add the social app in the admin interface. So in the admin interface, I want to try one of the simpler ones, so i chose OpenId. Since I don't have a facebook app id or anything yet, I figured with OpenId, I wouldn't need that.
I'm getting hung up on what to use for the Key and Secret to register the social app. I'm new to this stuff, but I thought that was more for OAuth. But if I don't include it, it flags the fields as red and demands them. Where do I find/generate a Key/Secret?
Also, to use OpenId, am I supposed to specify a site like Google or Yahoo, or is there just an "OpenId" site?
I'm still using manage.py runserver, if that makes any difference. But I thought I would still be able to get the page to "render."
What version of Python are you running? If you are using an old 2.6 version, then you may be running into the issue described here:
http://cuu508.wordpress.com/2011/01/27/keywords-must-be-strings/
Please let me know if that pinpoints your problem. If so, I'll check if I can make allauth play nice with your version...
Update: haven't had the time to test this myself yet, could you give this change a try?:
--- a/allauth/socialaccount/templatetags/socialaccount.py
+++ b/allauth/socialaccount/templatetags/socialaccount.py
## -13,7 +13,7 ## class ProviderLoginURLNode(template.Node):
def render(self, context):
provider_id = self.provider_id_var.resolve(context)
provider = providers.registry.by_id(provider_id)
- query = dict([(name, var.resolve(context)) for name, var
+ query = dict([(str(name), var.resolve(context)) for name, var
in self.params.iteritems()])
request = context['request']
if not query.has_key('next'):

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.

django social-auth redirecting to error url

I integrate django social-auth in my app.In settings i have given
AUTHENTICATION_BACKENDS,FACEBOOK_APP_ID,FACEBOOK_API_SECRET, social_auth.context_processors,SOCIAL_AUTH_PIPELINE etc.
when i click on facebook login it is redirecting to facebook app login when logged in it is redirected back to my app but redirecting to LOGIN_ERROR_URL and the user is not authenticated.
LOGIN_REDIRECT_URL = '/'
LOGOUT_URL= '/logout/'
LOGIN_ERROR_URL = '/login-error/'
SOCIAL_AUTH_LOGIN_REDIRECT_URL="/home/"
How can i solve this and get my app authenticated? Same is happening with google login also.Please help.
Thanks.
This question is very similar to a recent one I just answered: django social auth error after completing pipeline . Over there, I said:
A good place to start would be to look in social-auth's views.py, at the few places where the redirect to LOGIN_ERROR_URL happens (the variable url is set to LOGIN_ERROR_URL and then HttpResponseRedirect(url) is called). Add some print statements, or better, set breakpoints using the python debugger. If you run your app in the Django development server, the print statements will show up in the terminal in which you ran the server. Otherwise, they may show up in your server logs, depending on your configuration. You may also find django-debug-toolbar helpful.
Using print statements or the debugger, my workflow would be:
Figure out what line in views.py the redirect is triggered from
Figure out what condition causes that line to be reached
Inspect the variables leading to that condition
Sorry this is so general. Happy to help more if you can provide some more specific information.
Aaron
encountered same mysterious redirect to error url.
For me problem was with a typo in an argument of custom pipeline method.
Fixing the typo fixed the problem.