I have a React application for my business that has multiple clients. My architecture is set-up like this:
Server A - Main Application Server, only serves React app (url = https://example.net)
Server B - Business Client #1, serves their slightly customized React app (url = https://example2.net)
Server C - Business Client #2, serves their slightly customized React app (url = https://example3.net)
Microservice Server - Running a Java microservice (url = https://api.example.net - notice it's a subdomain of Server A)
Server A, B, and C are all talking to the Microservice Server for API calls. The API calls are using the native browser fetch() call with these options
var options = {
method: "{method}",
mode: "cors",
credentials: "include",
headers: { "Content-Type": "application/json" }
}
The server response has this header:
"Access-Control-Allow-Credentials", "true"
and uses the microservice's built-in
enableCorsForAllOrigins()
Now, this all works fine on Firefox, Chrome, IE, and Edge. However, it doesn't work on Safari (MacOS or iPhone) for Server B or Server C. It works fine on Safari on Server A.
The API calls are in this sequence...
POST https://api.example.net/login
GET https://api.example.net/users
On Safari, the first call is successful, but the second call fails with a 401 error. The 401 error is thrown from the microservice trying to get the Session attribute for the "currentUserId", which is null. In other words, Safari is not sending the cookie to the server. I've figured out that Safari doesn't like that the API calls are going to a different URL base than the client's server. (In other words, Server B making API calls to Server A).
To further verify this, if a user starts on Server B, then navigates to Server A and makes an API call (a bad login for example), and then goes back to Server B, then it works for them on Safari. It seems like Safari just needs to exchange a cookie on the Server A URL to get it working on every other server.
Now, my issue...how do I fix this? Users on Mac Safari and iPhone Safari on Server B and Server C are not able to use the application because their session cookies are not sent to the server. Has anyone seen this before? Does anyone have solutions? My first attempt was to create an iframe on Server B that loaded Server A's page, but that didn't work.
Many thanks in advance!