social-app-django | Python Social Auth - Application - Django | Authentication library
kandi X-RAY | social-app-django Summary
kandi X-RAY | social-app-django Summary
This is the Django component of the python-social-auth ecosystem, it implements the needed functionality to integrate social-auth-core in a Django based project.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Process an exception
- Raise an exception if the given exception is raised
- Returns the URL to redirect to
- Return the message
- A decorator that sets social strategy
- Load a backend
- Load a strategy
- Returns a list of search fields
- Return a list of all field names
- Return the user model
- Perform login
- Returns the session expiration time for the given provider
- Return the username of the given user
- Disconnect from an entry
- Removes models from the database
- Convert value to string
- Convert database value to python value
- Load the requirements txt file
- Return a User instance
- Destroys the model
- Get users by email address
- Returns the length of the username field
- Read the version number from the django
- Check if a user exists
- Delete expired codes
- Return the long description
social-app-django Key Features
social-app-django Examples and Code Snippets
Community Discussions
Trending Discussions on social-app-django
QUESTION
I am using social-app-django (part of python-social-auth) to implement Facebook login for the users of my Django site. I have a requirement that users must be found in the local user database before they can log in with Facebook. I have replaced the auth_allowed-part of the authentication pipeline, to perform this check:
...ANSWER
Answered 2019-Apr-17 at 11:46I think I solved the problem: I accidentally used
QUESTION
I'm trying to set verbose_name
for a model SocialAuthUser
from django_social.
I've tried to use proxy model, setting its Meta.verbose_name
to desired value, but had no success (probably I did it wrong). If it's the way to go, I can provide more details.
It would be great to avoid installing module from pip in editable mode just to replace verbose_name
in admin site.
Probably I can replace model name in admin site in some other way? I thought about adding custom link to admin site, but didn't research this method yet because it feels hacky.
...ANSWER
Answered 2018-Oct-13 at 18:05You almost got it right. For your changes on the proxy model to take effect you need to unregister the model from admin site first and then register the proxy model.
The example below is for social_django.Association
model.
QUESTION
Sometimes when user signups with his gmail account to my service and then he signups with his G Suite account, both emails create record in UserSocialAuth model but to same django User. Can someone help me understand why this happens and how to avoid it? I need both gmail accounts have separate django accounts.
I am using social-auth-app-django https://github.com/python-social-auth/social-app-django
My pipeline
...ANSWER
Answered 2018-May-04 at 08:17The issue seems to be with associate_by_email
config in the pipeline.
Removing that config would create a new user for all new social logins.
According to the doc:
if a user signed up with his Facebook account, then logged out and next time tries to use Google OAuth2 to login, it could be nice (if both social sites have the same email address configured) that the user gets into his initial account created by Facebook backend.
Read more here: http://python-social-auth.readthedocs.io/en/latest/use_cases.html#associate-users-by-email
QUESTION
Got an error when trying social-app-django (2.1.0), the error thrown was:
'AsgiRequest' object has no attribute 'session'
- Running with channels 1.1.8, Django 2.0.3, asgi-redis 1.2.0, python 3.6
- Running via python manage.py runserver (development environment) not uwgsi or nginx.
The occurs when trying to access /social/login/google-oauth2/ (authenticating with google account).
I have read about changing MIDDLEWARE_CLASSES to MIDDLEWARE but we have been using Django >=1.9 for a while so it has already been changed.
The traceback looks as follows:
Traceback (most recent call last):
File "/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35,in inner
response = get_response(request)File "/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)File "/lib/python3.6/site-packages/channels/handler.py", line 243, in process_exception_by_middleware
return super(AsgiHandler, self).process_exception_by_middleware(exception, request)File "/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)File "/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)File "/lib/python3.6/site-packages/social_django/utils.py", line 38, in wrapper
request.social_strategy = load_strategy(request)File "/lib/python3.6/site-packages/social_django/utils.py", line 23, in load_strategy
return get_strategy(STRATEGY, STORAGE, request)File "/lib/python3.6/site-packages/social_core/utils.py", line 279, in get_strategy
return Strategy(Storage, *args, **kwargs)File "/lib/python3.6/site-packages/social_django/strategy.py", line 39, in init
self.session = request.session if request else {}
AttributeError: 'AsgiRequest' object has no attribute 'session'
Middleware is the following (added because other WsgiRequest has no attribute session have been related with middleware):
...ANSWER
Answered 2018-Apr-25 at 16:36The problem was with middleware. I upgraded from Django>=1.9 to 2.0.3. SessionAuthenticationMiddleware was removed. When debugging middleware I found this:
ImportError: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class
The solution was to removed it. The reason why didn't it logged it out before it is unknown.
You can read more about this here:
QUESTION
I use this python-social-auth/social-app-django to connect my web with social media I want to ask how to handle errors when the same account is used to sign up?
For example, I signed up using facebook and I signed up again using twitter. both successfully registered into two separate accounts, when I logged in using my facebook and then on my account settings page, I want to connect my twitter that has been registered before it will display an error message
"AuthAlreadyAssociated at / oauth / complete / twitter /"
This message appears after I authorize on the twitter redirect page when it gets redirected back to my web.
In short, how to deal with accounts that have been registered in other accounts?
This is my views.py:
...ANSWER
Answered 2018-Feb-23 at 14:14Your question has been answered here: AuthAlreadyAssociated Exception in Django Social Auth
Basically the answer is to override the default method process_exception()
in the social_auth.middleware.SocialAuthExceptionMiddleware
class, and add this middleware to your settings.py.
More on how to override here: How do I handle exceptions on Python Social Auth
QUESTION
I'm using social-auth-app-django with FacebookOAuth2 backend what is based on python-social-auth and trying to set display=popup
at facebook authentication trought app settings.
Found this old issue for django-social-auth what is deprecated in favor of python-social-auth, but that options doesn't work.
...ANSWER
Answered 2017-Oct-29 at 10:15You can add below line to your settings
SOCIAL_AUTH_FACEBOOK_AUTH_EXTRA_ARGUMENTS = { 'display': 'popup', }
I found out it from the source code: https://github.com/python-social-auth/social-core/blob/master/social_core/backends/base.py#L203
QUESTION
I'm using social-auth-app-django
to support logins with social apps.
This code is on a angular-djangorest app, so basically the django doesn't serve the html pages.
Now from the docs, I can see that if I did serve the html pages, I would simply add the following line to generate the 'connect with' link:
...ANSWER
Answered 2017-Aug-29 at 09:12{% url 'social:begin' 'instagram' %}
in normal django python code would be:
from django.urls import reverse
reverse('social:begin', args=['instagram'])
ending up like this:
QUESTION
I am implementing social-app-django (not the deprecated one; the one that relies on Python-social-auth) with django 1.11 (not using Mongo). My application will need to store and manipulate a lot of data on users other than that which is fetched from their social media accounts at login.
I don't need to fetch or collect any extra data when the user authenticates, but various actions they perform on my site will need to be saved to their user model. I am wondering which of the following approaches is preferred (I've searched extensively online, but can't find a specific explanation of why to use one vs the other):
Create my own user model in my app's models.py (call it
MyUser
) that doesn't extend anything special, and then add a function in the authentication pipeline that associates the social-app-django user with a corresponding instance ofMyUser
. LeaveAUTH_USER_MODEL
andSOCIAL_AUTH_USER_MODEL
unchanged.or...
Create my own user model in my app's models.py, and in the project's settings.py set
AUTH_USER_MODEL
andSOCIAL_AUTH_USER_MODEL
to point toMyUser
. Leave the pipeline unchanged. In this case, I was wondering whether someone could clarify whatMyUser
and its manager should extend, and what I need to import in modules.py (I am confused because a lot of stack overflow posts are referring to deprecated versions of this module and I keep getting errors). Also, in this case should I be setting bothAUTH_USER_MODEL
andSOCIAL_AUTH_USER_MODEL
, or just one of them?
Do these two methods essentially achieve the same thing? Is one more reliable/preferred for some reason? Or, should I be doing both? Thanks very much for any assistance.
Another detail: I would like to be able to access the User database not only from the app I am currently building, but also from other apps (within the same Django project) that I will build in the future. Does this affect anything?
...ANSWER
Answered 2017-Aug-21 at 05:07Since I see this has a decent number of views I will post the solution I eventually came to.
Both django
and social-app-django
(or any other social auth module) make use of the default User
model for authentication. While it's possible to edit this model to add custom parameters, I don't recommend it. It's not good abstraction or modularization. If you make a mistake when configuring the model, you won't just break a specific feature on your site, but you might also break the authentication itself.
The only circumstances I can think of under which you'd want to edit the default user model itself is if you need to make changes that affect the authentication flow itself (for example, adding your own custom authentication provider).
It's much easier and safer to create a new model called UserProfile
, with a required one-to-one relationship to a User
object. Now, you can treat the User
object as the authentication part, and the UserProfile
object as the content/storage part. You won't have to mess with the User
model very often, and the UserProfile
model doesn't matter for authentication purposes. Note that in this configuration you should NOT need to change the AUTH_USER_MODEL
or SOCIAL_AUTH_USER_MODEL
fields in the settings.py file.
If you take this approach, you will need to add a custom step in the authentication pipeline in which you create a new UserProfile
object and associate it with the User
who is currently logging in.
QUESTION
I use Python Social Auth - Django to log in my users.
My backend is Microsoft, so I can use Microsoft Graph but I don't think that it is relevant.
Python Social Auth deals with authentication but now I want to call the API and for that, I need a valid access token. Following the use cases I can get to this:
...ANSWER
Answered 2017-May-31 at 09:09Using load_strategy()
at social.apps.django_app.utils
:
QUESTION
I want to create an app that uses the django admin, but allows logins via google (my company google account) in place of the django default ModelAdmin.
Currently, it looks like social-app-django (google) is the way to go, but after having installed and setup a project, it's not clear to me how I can allow django admin logins to use the social-app-django authentication. I've attempted to configure my project as described here http://python-social-auth.readthedocs.io/en/latest/configuration/django.html but it isn't clear how this can be integrated with the django admin.
I found this snippit (which seems out-of-date), and added it, but get a 404 when I try to goto /admin/
:
Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/accounts/login/?next=/admin/login/%3Fnext%3D/admin/ Using the URLconf defined in telos.urls, Django tried these URL patterns, in this order: ^login/(?P[^/]+)/$ [name='begin'] ^complete/(?P[^/]+)/$ [name='complete'] ^disconnect/(?P[^/]+)/$ [name='disconnect'] ^disconnect/(?P[^/]+)/(?P[^/]+)/$ [name='disconnect_individual'] ^admin/ The current path, accounts/login/, didn't match any of these.
If I remove the snippit, /admin/
will redirect to /admin/login/
and on login attempt return the ERROR text:
Please enter the correct username and password for a staff account. Note that both fields may be case-sensitive.
In addition to the configuration, I've added the following to my settings.py
:
projects/models.py (MyUser)
...ANSWER
Answered 2017-Apr-07 at 12:13Django Admin uses the auth
contrib application, so any authentication process triggers the same mechanism than a user logging in to a non-admin section and it will be processed by python-social-auth
backends if they are defined in AUTHENTICATION_BACKENDS
setting.
In order to make it work you will need to:
- Add a
Login with Google
link (linking to/login/google-oauth2
) to the login form. You can override the default login form by adding a admin/login.html template or by defining a custom AdminSite - Ensure that the user is flagged as
is_staff
, otherwise access to the admin will be forbidden.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install social-app-django
You can use social-app-django like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page