Build Single page application with React and Django Part 5.2-Exchange Github’s access token to JWT from Django/DRF server

Introduction
We have introduced how to get the access token from Facebook and exchange to JWT in the the previous article.
Github is also a popular platform for social login. The target of this article is to understand how to get access token from Github. Then we want to exchange the access token to JWT from our local Django server.
Agenda
It includes the following topics.
- Overview
- Get authorized code form Github
- Get access token from Github
- Set Django/DRF server
- Validation with Postman
About this series
The target of this series is to build a ReactJS single page application(SPA) with Django API server and deploy on Heroku.
- Part 1: Deploy Django application to Heroku and migrate PostgreSQL
- Part 2: Connect React App with Django App
- Part 3: Use JWT with DRF and tests endpoints on Travis-CI
- Part 4: Create Endpoints to Manipulate Resources
- Part 5.1: Exchange Facebook’s access token to JWT from Django/DRF
- Part 5.2: this article
- Part 6: Create Django Application’s sitemap on Heroku for SEO
- Part 7: How to Refactor Function Components with HOC?
- Part 8: Static Rendering with Next.js and Django on Heroku
- Part 9: Access Redux on the Next.js page-level
- Part 10: Improve SEO with Pyppeteer in Django
- Part 11: Theming with Redux and styled-component
Overview
There are four roles, Django server, ReactJS client, Github authorize server, and the user.

1.Get Authorized code form Github
Create a new OAuth apps from Github
- Login Github. Select Settings -> Developer settings -> OAuth Apps -> New OAuth App
- Copy the Client ID and Client Secret from the page

Create a ReactJS to retrieve the access token from Facebook
1.Install required packages
npm install react-github-login2.Create a ReactJS component
import React from 'react'
import GitHubLogin from 'react-github-login';import FacebookLogin from 'react-facebook-login';
const SignInForm = () => {
const ResponseGithubOnSuccess = (response) => {
console.log(response);
}const ResponseGithubOnFailure = (response) => {
console.log(response);
}
return (
<GitHubLogin
clientId="51b1a8ee5b7cad1e6a85"
redirectUri="http://localhost:3000/signin"
onSuccess={ResponseGithubOnSuccess}
onFailure={ResponseGithubOnFailure}/>
)
}3.We can use the component to get the authorized code from Facebook

2.Get Access token form Github
The next step is to get the access token from Github with the code, Client ID, and Client Secret. We can create an endpoint for the ReactJS component.
1.Add a new class in the views.py







