Hi! I am developing the same application with a different group for the same degree. We are having a similar problem, let me show what we have and maybe it will help you solve your problem or at least clarify it. First, we have the original request from the WebAPP:
export const login = async (providerURL : String) => {
const loginURL = await fetch('http://127.0.0.1:8082/auth/login',{
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
credentials: "include",
method: 'POST',
mode: 'cors',
body: JSON.stringify({provider: providerURL })
});
window.open(await loginURL.json()); //Redirect to provider auth
}
When the login process starts, we call the following function in our RestAPI, that links the WebAPP session with the provider session.
initLogin : async function (req:Request, res:Response){
// create a new Session
const session = new Session();
req.session.solidSessionId = session.info.sessionId;
//Redirect user to POD provider login
const redirectToSolidIdentityProvider = (providerURL : string) => {
res.status(200).json(providerURL);
};
// redirect handler will handle sending the user to their POD Provider.
await session.login({
// If login successfully, redirect here
redirectUrl: 'http://localhost:3000/auth/loginconfirm',
// Set user SOLID identity provider
oidcIssuer: req.body.provider,
// Application name to show when requesting data
clientName: "LoMap",
//handler to redirect to the provider login
handleRedirect: redirectToSolidIdentityProvider
});
},
If you take a look at the redirect handler, we redirect again to the WebAPP, since we need to close the original request we made. That fires the following
export const confirmLogin = (params : String) => {
return fetch("http://127.0.0.1:8082/auth/loginconfirm"+params, {
credentials: "include",
method: "POST"
})
}
Which calls the function in the RestAPI that is responsible for finishing the login process.
confirmLogin : async function (req:Request, res:Response){
// If we get here, the user has logged in successfully
// Recover session information
const session = await getSessionFromStorage(req.session.solidSessionId!);
// Complete login process using the data appended by the Solid Identity Provider
await session!.handleIncomingRedirect(`http://localhost:8082/auth${req.url}`);
// Session now contains an authenticated Session instance.
if (session!.info.isLoggedIn) {
return res.sendStatus(200);
}
return res.sendStatus(401)
},
And here is where we are having the problem. After redirecting to the provider, we are loosing the cookie, so when we try to recover the session from the storage in the RestAPI there is no matching solid session. Is there a way to keep the session of the WebAPP after redirecting to the provider?