So I would like to add SSO using Azure AD. My stack consists of a React app as frontend and a NestJS API as backend(decoupled). The scenario looks like the following
- User clicks login button
- I create a new window (popup) which leads the user to the Azure AD login page (step 3 in the diagram)
- After the user logs in to Azure AD successfully Azure AD will POST the SAML response to a redirect URL I have provided them (let's say http://myapp.com/saml) (step 5 in the diagram) (This redirect URL, to my understanding, has to be an endpoint in the NestJS api since React frontend can't handle post request.)
- NestJS will handle the post request get the info it needs, validates etc etc and then
NestJS has to return a Token to the frontend somehow
in order for the frontend to store that token in a cookie and be able use it in subsequent requests to the NestJS api so that NestJS will be able to know that this user is logged in. (Step 6)
My issue with this approach is that I don't know how will the client get the token when the the validation is completed from NestJS. If this was a coupled application this would not be an issue since the backend would handle the post request set a cookie and redirect the user. But in this case NestJS can't redirect the user since react handles the routing. What is the correct approach to handle this? I thought maybe this could work by using websockets...so that when NestJS handles the post request it can send a message to the user which message will contain the token and then the frontend can add it to a cookie and redirect the user to a protected page.