Not Found error after logging in with google using django-allauth - python

I am using django-allauth package and google provider for authentication in my django project. Everything worked fine in development however when I launched my project on the server, I got an error. When I press the "Log in with Google" button in my sign in page, I get redirected to the page where google asks me to choose my Google account to continue with.
Then after this step, where I get redirected to my site, I'm encountered with a Not Found error.
I tried a bunch of stuff found online but they didn't work.
here is my Google credentials authorized redirect URIs.
In my settings.py file I configured allauth as below:
# Django-allauth configs
AUTH_USER_MODEL = 'accounts.User'
AUTHENTICATION_BACKENDS = [
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
]
SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_SIGNUP_REDIRECT_URL = 'accounts:create_profile_url'
ACCOUNT_EMAIL_VERIFICATION = 'none'
LOGIN_REDIRECT_URL = 'dashboard_url'
ACCOUNT_FORMS = {
'login': 'accounts.forms.CustomLoginForm',
'signup': 'accounts.forms.CustomSignupForm',
'change_password': 'accounts.forms.CustomChangePasswordForm',
}
ACCOUNT_DEFAULT_HTTP_PROTOCOL='https'
and I've added 'allauth.urls' in my urlpatterns too
urlpatterns = [
...
path('accounts/', include('allauth.urls')),
...
]
I could really use some help. Thanks.

Related

How to change a URL that is configured inside a library?

Context: I need to configure OIDC using Django to allow my application to be accessed by users.
Problem: I'm using a library called mozilla-django-oidc that is pretty straight-forward, but when I test the configuration, it keeps returning the following error:
400 - Invalid redirect_uri
Cause: As I tested in Postman, this error occurs because the callback URL is wrong. When I searched more deeply mozilla-django-oidc, I've found it sets a standard URL path for callback (/oidc/callback/) which is not the URL allowed by the OIDC we need to access.
Key Question #1: How can I modify the mozilla-django-oidc code so that the standard callback URL path is what I need it to be?
Key Question #2: Is there anyway I can make these changes in my code, instead of mozilla-django-oidc?
Below are some settings of my Django code:
My Django - views.py
# Mozila OIDC configuration settings
OIDC_OP_AUTHORIZATION_ENDPOINT = "https://XXXXXXXXXXXXXXXXXXXXX"
OIDC_OP_TOKEN_ENDPOINT = "https://XXXXXXXXXXXXXXXXXXXXX"
OIDC_OP_USER_ENDPOINT = "https://XXXXXXXXXXXXXXXXXXXXX"
OIDC_RP_CLIENT_ID = "XXXXXXXXXXXXXXXXXXXXXXX"
OIDC_RP_CLIENT_SECRET = "XXXXXXXXXXXXXXXXXXXXXXX"
LOGIN_REDIRECT_URL = "https://myurl.com"
My Django - settings.py
# Add 'mozilla_django_oidc' to INSTALLED_APPS
INSTALLED_APPS = (
# ...
'django.contrib.auth',
'mozilla_django_oidc', # Load after auth
# ...
)
# Add 'mozilla_django_oidc' authentication backend
AUTHENTICATION_BACKENDS = (
'mozilla_django_oidc.auth.OIDCAuthenticationBackend',
# ...
)
My Django - urls.py
urlpatterns = patterns(
# ...
url(r'^oidc/', include('mozilla_django_oidc.urls')),
# ...
)
mozilla-django-oidc - urls.py
urlpatterns = [
url(r'^callback/$', OIDCCallbackClass.as_view(),
name='oidc_authentication_callback'),
url(r'^authenticate/$', OIDCAuthenticateClass.as_view(),
name='oidc_authentication_init'),
url(r'^logout/$', views.OIDCLogoutView.as_view(), name='oidc_logout'),
]
Other parts of mozilla-django-oidc library can be found at https://github.com/mozilla/mozilla-django-oidc/tree/master/mozilla_django_oidc

Django Rest Framework and AWS Cognito

Currently, I am using django-warrant to utilize cognito (JWT) based authentication to access APIs. After creating pool and app, I have set up following in my settings file:
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'django_warrant.backend.CognitoBackend',
]
COGNITO_USER_POOL_ID = 'poolid'
COGNITO_APP_ID = 'app id'
COGNITO_ATTR_MAPPING = {
'email': 'email',
'given_name': 'name',
'family_name': 'last name',
}
COGNITO_CREATE_UNKNOWN_USERS = False
AWS_ACCESS_KEY_ID = 'access_key'
AWS_SECRET_ACCESS_KEY = 'access_key_secret'
In Midddleware, I have added:
MIDDLEWARE = [
.............,
'warrant.django.middleware.APIKeyMiddleware',
..............,
]
In Installed apps, I have added,
INSTALLED_APPS = [
............,
'django_warrant',
............,
]
In urls.py, I have added:
path('accounts/', include('django_warrant.urls'))
When I try to hit accounts/login url, it is throwing the error of missing templates.
As I am using it for the first time, I am clueless how to proceed further with it to map django users with cognito users. I have searched tutorials related to this but found None. Please provide me guidance so that I can manage to proceed further.

Email verification and password reset - django rest framework and angularjs

How do I implement the built in views for password-reset in the django.rest.auth and how do I create an email verification system for registration using the django rest framework and angularjs?
I have been searching for a tutorial or some good documentation that on how to implement django's send_email function in a website using the django rest framework and angular js but I haven't been able to find any.
What I need...
when a new user registers a url must be generated for them to confirm their email address
this url must be automatically sent to the user's given email
after the user is sent to this link and confirms their email address their status must be changed from new_user.is_active = False to new_user.is_active = True
What I have...
registration form that sends a post request to my register endpoint
the new user data is then unpacked, validated, and saved in my register view
in settings.py i have added this...
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myemail#gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
in my urls.py i have added this...
from django.conf.urls import url
from rest_auth.views import PasswordResetView, PasswordResetConfirmView
urlpatterns = [
url(r'^password/reset/$', PasswordResetView.as_view(), name='password_reset'),
url(r'^password/reset/confirm/$', PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
]
So my question is how do I implement these views and urls to my project and how to I create email confirmation using the from django.core.mail import send_mail
Thanks in advance
After the user fills the registration form you could ask for a verification code. This verification code will be sent to the email address provided in the registration form. On correctly entering the verification code you can set the users to active.
For anyone still looking for solutions, django-allauth is a good choice. you can override PASSWORD_RESET_CONFIRM_SERIALIZER to make the user active.

Django login with facebook Error: Given URL is not allowed by the Application configuration

I am tired of this issue, please somebody can explain me where am I wrong?
I installed django-social-auth and add settings.py to installed apps :
'social_auth'
I added these lines to settings.py:
AUTHENTICATION_BACKENDS = ( 'social_auth.backends.facebook.FacebookBackend',
'social_auth.backends.contrib.github.GithubBackend',
'django.contrib.auth.backends.ModelBackend',)
SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'
SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'
SOCIAL_AUTH_RAISE_EXCEPTIONS = False
SOCIAL_AUTH_FORCE_POST_DISCONNECT = True
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True
SOCIAL_AUTH_USER_MODEL = 'auth.User'
FACEBOOK_APP_ID = '11036686*****'
FACEBOOK_API_SECRET = '6290e378b078cc0cad*******'
SOCIAL_AUTH_ENABLED_BACKENDS = ('facebook', 'github')
context_processors :
'social_auth.context_processors.social_auth_by_name_backends',
'social_auth.context_processors.social_auth_backends',
'social_auth.context_processors.social_auth_by_type_backends',
'social_auth.context_processors.social_auth_login_redirect',
Then I go to facebook developers page and add:
appdomains:
localhost
Site URL
http://localhost:8000/
And
I click Embedded browser OAuth Login and enabled.
And I am getting this error:
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.
What am I missing? Thanks for help.
Try to run your server as ./manage.py runserver localhost:8000
and in your browser go to localhost:8000 instead of http://127.0.0.1:8000/

Unable to log in to the django admin page due to django-social-auth backends enabled

I have used django-social-auth in my project to enable the user to sign in using different social websites like twitter or facebook. For that I have to enable different authentication backends in settings.py like this:
AUTHENTICATION_BACKENDS = (
'social_auth.backends.twitter.TwitterBackend',
'social_auth.backends.facebook.FacebookBackend',
)
By enabling these backends I can not login to django admin page. Where an occurs saying that username of password not correct for a staff user.
I have disabled these backends then admin page is working but I am not able to achieve the functionality of sign in using different social websites. Please help me out in this problem. All the suggestions will be appreciated.
Add django.contrib.auth.backends.ModelBackend to this list:
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'social_auth.backends.twitter.TwitterBackend',
'social_auth.backends.facebook.FacebookBackend',
)
when no AUTHENTICATION_BACKENDS is specified, backends list defaults to sole ModelBackend

Categories