I'm stuck on this for the past few days. I'm having an issue authenticating with Oidc, I'm trying to redirect to a signin-callback.html after authentication but I'm unable to call an HTML page directly from my react app, during my research I've seen examples of this using typescript, but I'm not sure why it's not working in my JS web app.
from my research online it seems that i need to redirect to the signin-callback.html in order to get my auth token but that's where im stuck
any help would be appreciated
signin-callback.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Authentification callback processing..</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<h1>Authentification callback processing...</h1>
<script src="oidc-client.min.js"></script>
<script>
new Oidc.UserManager({ response_mode: "query" }).signinRedirectCallback().then(function () {
console.log("Ter")
window.location = "index.html";
}).catch(function (e) {
console.error(e);
});
</script>
</body>
</html>
settings
const settings = {
authority: `${process.env.REACT_APP_AUTHORITY}`,
client_id: `${process.env.REACT_APP_CLIENT_ID}`,
redirect_uri: `${process.env.REACT_APP_REDIRECT_URI}`,
response_type: `${process.env.REACT_APP_RESPONSE_TYPE}`,
metadataUrl: `${process.env.REACT_APP_METADATA_URL}`,
};
main.js
const getUserInfo = async () => {
userManager.getUser().then(async (user) => {
if (user) {
console.log('User has been successfully loaded from store.');
// console.log(username)
dispatch({ type: "JWT", payload: { displayName: username.data.DisplayName, user: user } });
} else {
console.log('You are not logged in.');
userManager.signinRedirect();
}
});
}
useEffect(() => {
// Test()
getUserInfo()
}, [])
In an SPA you should be able to just set the redirect to the SPA's main URL. Then, whenever the page loads, look for an OIDC login response, via the
code,errorandstateparameters.If found, then calluserManager.signInRedirectCallback(). I used to use this library a lot, and here are some examples:Here is a React based example, to handle page loads and check for an OAuth response. Note that this does not use the oidc-client library and instead uses a more up to date
Back End for Front Endapproach.