Episyche
React/Single sign-on (SSO)/
Published on
Django REST framework (DRF) is a powerful and flexible toolkit for building Web APIs.Its main benefit is that it makes serialization much easier. Django REST framework is based on Django's class-based views, so it's an excellent option if you're familiar with Django. To know more about relative links click here
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. and NPM is a package manager for Node. js packages. The NPM program is installed on your computer when you install Node.js. To know more about relative links click here
ReactJS is much easier to learn and use. ReactJS is a free and open-source front-end JavaScript library for building user interfaces based on UI components. to create interactive applications for mobile, web, and other platforms. To know more about relative links click here
Single sign-on (SSO) is a time-saving and highly secure user authentication process. SSO lets users access multiple applications with a single account and sign out instantly with one click.
Steps:
Check out this tutorial, to create a client Id and client secret.
Before we create React App we need to install node.js.
if you already installed node.js please ignore this step 2 and go to step 3
After installing Node.js open the terminal or command prompt and create the React app with the following commands
1npx create-react-app frontend
A sample screenshot of React app files is shown below.
After creating the React app then install the react-login-github
commands
1npm i react-login-github
In src/App.js
, add the following code.
1import './App.css';
2import LoginGithub from 'react-login-github';
3import github from "./github.png"
4
5function App() {
6 function onSuccess(e) {
7 fetch("http://127.0.0.1:8000/github/", {
8 method: "POST",
9 body: JSON.stringify({ "auth_token": e.code }),
10 headers: {
11 'Content-Type': 'application/json; charset=utf-8'
12 }
13 })
14 .then((res) => res.json())
15 .then((response) => {
16 document.getElementById("email_id").innerText = response['email']
17 document.getElementById("auth_token").innerText = response['tokens']
18 })
19
20 }
21 function onFailure(e) {
22 alert(e)
23 }
24 return (
25 <div className="App">
26 <LoginGithub
27 clientId="Github client Id"
28 onSuccess={onSuccess}
29 onFailure={onFailure}
30
31 className="github">
32 <img src={github} alt="Sign in with github" className='github-image' ></img>
33 <h2 className='github-name'>Sign in with github</h2>
34
35 </LoginGithub>
36 <div className="show-user_info">
37 <div >
38 <label className="info">Email Id:</label>
39 <label id='email_id'></label>
40 </div>
41