Facebook authentication error in Heroku based django website - python

I have fully created a Django website with python-social-auth for facebook authentication and have hosted it on heroku(free version). The problem however is,that my Facebook authentication,which was working perfectly locally,is not working and it throws an error as follows:-
Given URL is not allowed by the Application configuration: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
I have configured my facebook settings , wherein the site url is the one hosted on heroku (https://quiet-hamlet-3248.herokuapp.com/). Also,I haven't changed my API keys/secret.
Any help would be appreciated.

So I just figured it out.
As mentioned here , one needs to update his settings file to include the line SOCIAL_AUTH_REDIRECT_IS_HTTPS = True
This is because heroku fails to pass the headers required to identify the app.

Related

How to restrict the login google api with specific domain name only?

I'm creating a web application which I'm using Google API for authentication. Also, the library that I've applied was social-auth-app-django. Then, my goal is to allow only specific domain name like user#example.com with a domain of example.com.
Upon reading its documentation this line of code should be added to settings.py SOCIAL_AUTH__WHITELISTED_DOMAINS = ['foo.com', 'bar.com'] however, it is not working to me.
settings.py configuration
AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS = ['example.com.hk']
How can I restrict the google api to only allow the specified whitelisted domains?
You have to add and specify the authorize domains to your google API credentials.

Django 404 page not found

I've been doing a lesson on udemy trying to make a clone site of producthunt using django. I've tried asking there, but I don't get an answer. For some reason when I run the exact same code as the instructor, I get an error when trying to load the page localhost:8000/signup or any other pages other than the home page.
I get this error:
error
Settings file:
settings
Main urls:
main urls
app urls (named accounts):
app urls
views:
app views
finally my file structure for reference:
directory
I've been trying to figure it out with no avail. Any help would be great thank you.
signup is a route in the accounts app. In your main urls.py you include your accounts.urls under accounts/. Putting that all together, with your current structure you should be hitting accounts/signup rather than just signup.
There's no url /signup in your web.
You're url is for accounts/signup/

Django-allauth - URL isn't included in the app's domains

I'm trying to set Facebook login and registration on my web page (localhost for now).
Installed allauth
Set settings.py
Created an facebook app
And now, when I click on http://127.0.0.1:8000/accounts/login/ facebook href, it returns this alert:
Can't Load URL: The domain of this URL isn't included in the app's
domains. To be able to load this URL, add all domains and subdomains
of your app to the App Domains field in your app settings.
According to sites, I've set domain name (in Django-admin Sites) to
localhost
What should I do to make it work?

No csrf token for Django web page

I have a new Django app with REST endpoints and static html page that triggers XMLHttpRequest REST queries. POSTs fail with "CSRF cookie not set.".
If I open a client debugger, document.cooke returns "". AFAIK, this should have "csrftoken".
In settings.py, MIDDLEWARE_CLASSES contains 'django.middleware.csrf.CsrfViewMiddleware' by default. Any idea what might be wrong?
Add ensure_csrf_cookie decorator to your view.
https://docs.djangoproject.com/en/1.9/ref/csrf/#django.views.decorators.csrf.ensure_csrf_cookie
If that doesn't help you might want to read these docs
https://docs.djangoproject.com/en/1.9/ref/csrf/#ajax

Redirect example.com users to example.com/#/login

I am working on a project that uses Django and Angular. I do not have a background as a web developer so please try to explain your answer so that a novice person can understand it.
Basically I want to make it so that the login page is the default page instead of the index page.
I currently have the following url handler in my main Django project urls.py:
url(r'^$', 'core.views.generic.index')
I also have another urls.py in an app called core that sends visitors to the login page:
url(r'^/login$', private.MeLogin.as_view())
Now I want the login page to become the default page instead if the index page. How can I do that?
I have tried adding the following the the views file in the core app:
#login_required(redirect_field_name='', login_url='#/login')
def index(request):
return render_to_response('html/index.html', locals(), context_instance=RequestContext(request))
Unfortunately I get the message
This webpage has a redirect loop
I do not know how to solve this problem. Basically I want users to be redirected to the login page if they enter any URL that is not handled by other URL handlers. When they successfully log in they are redirected to a dashboard page automatically.
EDIT:
The login page URL is handled in the core urls.py file and points to a different view than index.
url(r'^/login$', private.MeLogin.as_view())
Web servers, in this case Django, do not see the fragment after the #. You are redirecting from / to /, creating a redirect loop.
If you want to redirect to the Django login url, you need login_url='/login'.
As an aside, you should remove the leading slash from your regex r'^/login$.
In #login_required(redirect_field_name='', login_url='#/login')
remove redirect_field_name='', it really is not neccessary and make sure that #/login in login_url='#/login is the same as in your url.py file:
like
views.py
#login_required(redirect_field_name='', login_url='accounts/login/')
as
url.py
url(r'^accounts/login/', auth_views.login),
I assume your Angular & Django apps are running in two seperate ports, like:
Django on port 8000
Angular on port 1000
So if you give /#/login it will redirect for the same with Django port (8000/#/login).
So why don't you give the full URL www.example.com/#/login?

Categories