API calls for authstart and authlogin; Call authlogin with code and redirect URI to do the token exchange on the backend

This commit is contained in:
2023-07-09 07:58:31 +08:00
parent e80c3528db
commit b1f1b34924
2 changed files with 46 additions and 4 deletions
@@ -1,9 +1,11 @@
import React, {useState, useEffect} from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import React, { useEffect } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import usersService from '../../../services/UsersService';
function Redirect() {
const location = useLocation();
const navigate = useNavigate();
const userApi = new usersService();
const queryParams = new URLSearchParams(location?.search);
const codeResponse = queryParams.get("code");
@@ -13,7 +15,36 @@ function Redirect() {
navigate('/login', {replace: true})
return
}
console.log(codeResponse)
console.log(codeResponse);
/*
POST /token HTTP/1.1
Host: oauth2.googleapis.com
Content-Type: application/x-www-form-urlencoded
code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7&
client_id=your_client_id&
client_secret=your_client_secret&
redirect_uri=https%3A//oauth2.example.com/code&
grant_type=authorization_code
*/
var reqData = {
code: codeResponse,
redirect_uri: process.env.REACT_APP_GOOGLE_REDIRECT_URL,
};
userApi
.authStart(reqData)
.then((res) => {
console.log(res.data);
if (res.status != 200 || res.internal_return < 0) {
return;
}
// "{"message":"Endpoint not found.","URI":"http:\/\/localhost:9083\/index.php\/en\/wrench\/api\/v1\/authstart"}[]"
const data = JSON.parse(res.data.replace('[]',''));
alert(data.message);
})
.catch((error) => {
console.log(error);
});
},[])
return (
<div>Redirecting ... </div>
+12 -1
View File
@@ -1,4 +1,3 @@
import React from "react";
import Axios from "axios";
class usersService {
@@ -26,10 +25,22 @@ class usersService {
};
return this.postAuxEnd("/dashdata", postData);
}
logInUser(reqData) {
localStorage.setItem("session_token", ``);
return this.postAuxEnd("/userlogin", reqData);
}
authStart(reqData) {
localStorage.setItem("session_token", ``);
return this.postAuxEnd("/authstart", reqData);
}
authLogin(reqData) {
localStorage.setItem("session_token", ``);
return this.postAuxEnd("/authlogin", reqData);
}
marketJobData(reqData) {
var postData = {
uuid: localStorage.getItem("uuid"),