12/10/2023 0 Comments Django rest framework reactUpdate the accounts/views.py file with the following code.ġ from rest_framework.generics import GenericAPIViewģfrom rest_framework.response import Responseĥfrom rest_framework.permissions import AllowAnyĦfrom rest_corators import permission_classesĩclass FacebookSocialAuthView(GenericAPIView):ġ0 11 serializer_class = FacebookSocialAuthSerializerġ6 Send an access token as from facebook to get user informationġ8 19 serializer = rializer_class(data=request.data)Ģ0 serializer.is_valid(raise_exception=True)Ģ1 data = ((serializer.validated_data))Ģ2 return Response(data, status=status.HTTP_200_OK) Sample code for the /accounts/serializers.py can be found in the following GitHub URL.įacebook_sso_django_reactjs_example/serializers.py at main Please login again.'Ģ5 provider=provider, user_id=user_id, email=email, name=name) You can run your app via CLI with the following command and view it in your browser:Ĥfrom import register_social_userĦ 7class FacebookSocialAuthSerializer(serializers.Serializer):Ĩ """Handles serialization of facebook related data"""ġ0 11 def validate_auth_token(self, auth_token):ġ2 user_data = (auth_token)Ģ2 'The token is invalid or expired. episyche/facebook_sso_django_reactjs_example.Sample code for the App.js file can be found in the following GitHub URL.įacebook_sso_django_reactjs_example/App.js at main How it Works:ġ import FacebookLogin from 'react-facebook-login' ĩ body: JSON.stringify(),ġ1 'Content-Type': 'application/json charset=utf-8'ġ6 document.getElementById("email_id").innerText = resġ7 document.getElementById("auth-token").innerText = resĬopy Copy Copy Copy Copy Copy Copy Copy Copy Copy Copy Copy Copy Copy SSO lets users access multiple applications with a single account and sign out instantly with one click. Single sign-on (SSO) is a time-saving and highly secure user authentication process. To know more about relative links click here Single sign-on(SSO): to create interactive applications for mobile, web, and other platforms. ReactJS is a free and open-source front-end JavaScript library for building user interfaces based on UI components. To know more about relative links click here React: The NPM program is installed on your computer when you install Node.js. Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on a JavaScript Engine and executes JavaScript code outside a web browser. To know more about relative links click here Node.js : Django REST framework is based on Django's class-based views, so it's an excellent option if you're familiar with Django. Introduction : Django (Django rest Framework):ĭjango REST framework (DRF) is a powerful and flexible toolkit for building Web APIs.Its main benefit is that it makes serialization much easier.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |