Github Authorization via pkce
I am making a github authorization via react and spring boot but i am getting 401 error while getting the access token ..
React frontend :
React frontend :
import React, { useEffect } from "react";
import axios from "axios";
const GitHubCallback = () => {
useEffect(() => {
const handleGitHubCallback = async () => {
const code = new URLSearchParams(window.location.search).get("code");
const codeVerifier = sessionStorage.getItem("code_verifier"); // Use sessionStorage as per your code
if (code && codeVerifier) {
try {
const params = new URLSearchParams();
params.append("code", code);
params.append("codeVerifier", codeVerifier);
const response = await axios.post("http://localhost:8080/api/auth/github", params, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
});
// Handle the received JWT or token
console.log("Access Token:", response.data.access_token);
} catch (error) {
console.error("GitHub OAuth Error:", error);
}
}
};
handleGitHubCallback();
}, []);
return <p>Processing GitHub login...</p>;
};
export default GitHubCallback;import React, { useEffect } from "react";
import axios from "axios";
const GitHubCallback = () => {
useEffect(() => {
const handleGitHubCallback = async () => {
const code = new URLSearchParams(window.location.search).get("code");
const codeVerifier = sessionStorage.getItem("code_verifier"); // Use sessionStorage as per your code
if (code && codeVerifier) {
try {
const params = new URLSearchParams();
params.append("code", code);
params.append("codeVerifier", codeVerifier);
const response = await axios.post("http://localhost:8080/api/auth/github", params, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
});
// Handle the received JWT or token
console.log("Access Token:", response.data.access_token);
} catch (error) {
console.error("GitHub OAuth Error:", error);
}
}
};
handleGitHubCallback();
}, []);
return <p>Processing GitHub login...</p>;
};
export default GitHubCallback;