Django online users with rest framework - python

I had used django-online-users to get online users and it worked fine. But the problem is that i am not able to get online users in django rest framework i.e. users making api calls from react to backend server.
I am only getting direct logged in users log in admin panel.
Please suggest a way to use it with django rest framework.
Thanks.

Related

how to retrieve the token generated while using django allauth and django-rest-auth with django rest framework

I am using django allauth and django-rest-auth from this tutorial to generate a token for django rest framework. The tutorial can be found on this page, at the bottom. (https://www.softcover.io/read/92780ad5/django_book/token_authentication)
I am able to generate the token after accessing api/dj-rest-auth/register/, which is the sign up page from the browsable API.
Now the issue is that i am on python3 manage.py shell and i am trying to retrieve any of the token generated for either user test001 or test002
does any one know how to do it? I am having a hardtime to achieve it
Thanks in advance
tokens_for_user1_and_user2 = APIToken.objects.filter(user__name__in=["test001","test002"]).all()
I guess ... or something like that

React JS Frontend with DRF backend authentication

Have developed a pretty decent API utilizing Django and Django Rest Framework to make my data available for consumption. Decided to build a React JS front end to be a little more dynamic than the standard Django templates. I have numerous views within DRF which work fine, I'm able to make calls against them and get or post to them no problem. Currently I'm working on implementing a login capability for the React frontend so that users will be given access to a couple protected views and will be presented with information relevant to them.
Maybe I'm not understanding what is supposed to be happening, web development isn't exactly my area of expertise. Have referenced the Django documentation a bunch trying to understand sessions and session authentication. I have a 'login' view which is taking a username and password provided to it, searching for a related 'User' record based off of the username and attempting to leverage the django.contrib.auth login method; this all seems to be working, the user is getting authenticated. After this step, I'm pretty much completely lost as to what is supposed to happen.
In my React component, I've attempted sending the username as a 'session' attribute in the header, I've tried including the csrftoken in the headers, I've tried to just enable 'withCredentials' in the callout. Really not sure what I'm supposed to be doing here. Is my login view supposed to be returning some attribute that I would then store in the react components to include in calls to protected views?
Been stuck on this for a while and am getting lost in reading documentation.
Thanks

Django with DRF and OAUTH2.0

I'm trying development a system with Django and Django Rest Framework, since i started i found out two problem, first for authentication second for permissions, i want use OAuth2.0 to make it possible, and django-oauth-toolkit.
Now, i wanna know how i authenticate a user and give the right for his, if he is admin or normal user?

Push notification in django rest

I am working on a attendance registration system where a user of an office can make a leave request. When any user makes a leave request, it must be notified to admin. How do I implement it ?
I had seen django-fcm for push notification. But I am using django rest framework . Can I implement django-fcm with django rest ?
If any tutorials link would be more helpful
This is not a very hard, clone the fcm-django-web-demo project and try coding in Django shell...

What is the right way to use django-allauth with tastypie?

I'm writing a Django app that uses django-allauth for Facebook integration, and uses django-tastypie for a backend for an iOS app. The iOS app will use the native Facebook iOS SDK. I'd like to be able to sign up and verify both Facebook and non-Facebook users from the iOS app, in addition to the website.
The issue is that django-allauth doesn't seem to have an API that can be accessed externally. The only clean way to plugin to allauth's functionality seems to be via Django template tags. Is there a way I can expose this functionality to be used with tastypie?
Django-allauth is all open source, so I've tried to parse through the code. My initial idea is to authenticate users on the iOS side using the native Facebook SDK, and then manually fill in information for SocialAccount, SocialToken, and add the SocialAccount to SocialApp (those are all django-allauth models). However, that seems to be quite a hacky solution. I'd love a way to cleanly create all those models given a Facebook ID, or something similar.
Update:
There's been some discussion concerning this issue on the GitHub. Basically, there's no built-in functionality yet. I'm going to whip up a custom solution that only deals with Facebook (because that's all I'm using in my application). I'll post what I did here later if it works.
Quick look into django-allauth shows that they are using SocialAccount model to hold data on specific method of authentication and type of social account.
You need to create an API endpoint based on SocialAccount model. You need to pass there variables like: account type (facebook, local, twitter etc), additional auth variables needed by social auth providers. Then, in your code you can create SocialAccount model instances, feed with data received from API endpoint call and trigger corresponding auth call via django-allauth. Finally you should return result of your auth call.
I don't see a big reason to use django-allauth for local/facebook auth only, with some small effort you can have whole range of social auth providers.
I used requests library to deal with facebook API and it works great, I think no social login plugin for Django works for others but the author, if you want to do something seriously.
PS. I used django-rest-framework to build the rest backend for mobile apps, also including local account login and social site login.

Categories

Resources