After installing
social-auth-core
social-auth-app-django
on Django 4.0.6 and including to the INSTALLED_APPS and made everything on documents I got this error
'DjangoStrategy' object has no attribute 'get_backend'
This error happens when I click on login link on this URL http://localhost/login/google-oauth2/
In settings.py I have this backends
AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
Also, I am using channels and ASGI/Channels version 3.0.5
Related
I am using allauth with wagtail. I have name my site 'mysite' in the wagtail admin, but when sign up emails refer to 'example.com'
My settings.py has apps in the following order
[ ...
'django.contrib.auth',
'django.contrib.sites',
"allauth",
"allauth.account",
"allauth.socialaccount",
"allauth.account",
"allauth.socialaccount",
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail.core',
]
It sounds as though this might be related to the conflict between django and wagtail described here https://github.com/wagtail/wagtail/issues/2840. However it looks as though that issue has been closed and I am using recent version (Django==3.2.11, django-allauth==0.47.0, wagtail==2.15.1)
This is the expected behaviour - django-allauth is a Django package, not a Wagtail-specific one, and always uses Django's site model even when Wagtail is active. To update the site name, log in to the Django admin backend (as distinct from the Wagtail one - this can be found at http://localhost:8000/django-admin/ if you set up your project with the wagtail start command) and go to the Sites item.
The issue being fixed in https://github.com/wagtail/wagtail/issues/2840 was that Wagtail and django-allauth could not coexist at all, due to both of them trying to set a conflicting request.site variable.
I am a beginner level DRF developer. I am trying to integrate Keycloak with Django Rest Framework. Unfortunately, I was unable to find any type of help/blog/tutorial online.
You can use KeyCloack's Oauth2 API to authenticate and authorize your djagno users. Is is the same as implementing Sign-in with Google or any other provider.
My favorite package to implement social auth is python-social-auth, and it even has an existing backend for KeyCloack.
Here is how a configuration for Oauth2 against KeyCloack should look like:
First, setup social auth in your project like so
$ pip install social-auth-app-django
In your settings.py
INSTALLED_APPS = (
# ...
'social_django',
# ...
)
AUTHENTICATION_BACKENDS = (
'social_core.backends.keycloak.KeycloakOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
# Add you connection settings here
SOCIAL_AUTH_KEYCLOAK_KEY = 'test-django-oidc'
SOCIAL_AUTH_KEYCLOAK_SECRET = 'a7a41-245e-...'
SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY = \
'MIIBIjANBxxxdSD'
SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL = \
'https://iam.example.com/auth/realms/voxcloud-staff/protocol/openid-connect/auth'
SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL = \
'https://iam.example.com/auth/realms/voxcloud-staff/protocol/openid-connect/token'
In your urls.py
urlpatterns = [
...
path('auth/', include('social_django.urls', namespace='social'))
...
]
Then add this to your login page template:
Login with KeyCloack
Hey guys I am new to django , I am learning to build some application using it , so I am following some example instructions of some blog. In that there is need of configuring an social authentication django package with my app.
I am not getting where to add this line please point out.
Add social_django to INSTALLED_APPS Add
social_core.backends.yammer.YammerOAuth2 to AUTHENTICATION_BACKENDS
Set LOGIN_REDIRECT_URL = ‘/badges/’ Set LOGIN_URL = ‘/login/yammer’
I have a working Django REST API backend. I was previously using session authentication, but would like to move to token based for scaling across multiple servers. I have been researching this for a couple days now and I have not found an answer to my problem. I added the djangorestframework-jwt package to my application but when I try to authenticate is always returns:
{"non_field_errors":["Unable to login with provided credentials."]}
I see in the jwt package where this error is, and can follow the code back through the authentication process. I do not see any errors in the auth process. When I try to create a user with those credentials it says that a user already exists, so I know it is hitting the correct user table. I am not sure why the obtain_jwt_token endpoint will not authenticate my credentials. Below are relevant sections of my django app. Any help would be greatly appreciated. If I am leaving anything out that could help figure this out please let me know and I will upload it. Thanks,
app/settings.py
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE': 100,}
app/urls.py
urlpatterns = patterns('',
# Api
url(r'^api/', include(router.urls)),
url(r'^api/stats', statsviews.StatsView.as_view()),
url(r'^api/testing', statsviews.TestView.as_view()),
url(r'^api/login', 'rest_framework_jwt.views.obtain_jwt_token'),
url(r'^api/logout', logout, {'next_page': '/api/login'}),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
)
curl command
curl -d "email=test#myemail.com&password=test123" http://webhost.mywebsite.com:8080/api/login/
I have a very similar setup to you. A simple app, utilizing vanilla DRF JWT authentication. The only difference that I can tell is that I have rest_framework_jwt included in my INSTALLED_APPS list:
INSTALLED_APPS = (
...
# Third Party Dependencies
'rest_framework',
'rest_framework_jwt',
'corsheaders',
....
Try adding that and see where it gets you.
I encountered the same problem too,and finally found the way out.
following the quick start guide (http://www.django-rest-framework.org/tutorial/quickstart/) , using python manage.py migrate to create table structure; using python manage.py createsuperuser to create an initial user named admin with a password of "password123"; (attention: the passwords mismatch in guides)
now it should be ok.
$ curl -X POST -d "username=admin&password=password123" http://127.0.0.1:8000/api-token-auth/
{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwidXNlcl9pZCI6MiwiZW1haWwiOiJhZG1pbkA3amdvLmNvbSIsImV4cCI6MTQ3MDY0NjY4Mn0.Dg4KW5pHHJfuaRzjqHTu8kYIzkq8js9}
I installed askbot through pip into my existing local Django project. I merged the askbot settings & Uls files with my existing files. When I go to 127.0.0.1:8000/ its getting redirected to 127.0.0.1:8000/questions. And I can see all my existing users but no sign in is available.
I see a lot of Url redirects not working because of reverse, like Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. In my backend database all the tables are looking fine. But users are not integrated with askbot, also there is AttributeError with context_processor.py.
How to allow my existing and future users, who are authenticated by my existing django project use askbot seamlessly?
How does the askbot admin integrates with my existing admin site?
Can we convert Jinja2 template to Django tempalte?
This is my template context tuple
TEMPLATE_CONTEXT_PROCESSORS = (
#askbot
#'django.contrib.auth.context_processors.auth',
'django.core.context_processors.request',
#"allauth.context_processors.allauth",
#"allauth.account.context_processors.account",
'askbot.context.application_settings',
#'django.core.context_processors.i18n',
'askbot.user_messages.context_processors.user_messages',#must be before auth
'django.contrib.auth.context_processors.auth', #this is required for admin
'django.core.context_processors.csrf', #necessary for csrf protection
###############askbot ended###########
#"django.contrib.auth.context_processors.auth",
"django.core.context_processors.media",
'django.core.context_processors.static',
#"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
"apps.common.utils.context_processors.app_wide_vars",
"apps.common.context_processors.feedback_questions",
"allauth.context_processors.allauth",
"allauth.account.context_processors.account",
#"allauth.socialaccount.context_processors.socialaccount",
#'cms.context_processors.media',
'sekizai.context_processors.sekizai',
#'admintools_bootstrap.context_processors.site',
)