I'm posting log in form data containing username and password to an endpoint using Unity. I receive a success response containing expected credentials (as a session cookie) and subsequent communications are completed successfully when testing this in the Unity Editor.
When I deploy and build the project as WebGL I do not receive the 'Set-Cookie' header from my log in request. This causes all subsequent communications to fail unauthorized 401.
- The log in WebGL post returns a success response.
- When inspected in the browser, I see the success response returns the expected session cookie credentials with the header 'Set-Cookie'.
- But the UnityWebRequest returns null when queried for 'Set-Cookie' response header. Some headers are still present, but most appear stripped.
- WebGL build is deployed and played from https enabled server - this is a different server from the log in server
I think there is some security (CORS?) stripping these credentials before the response is returned to my program. Allow credentials and Origin response headers appear correct. 'Set-Cookie' response header format is:
Set-Cookie: SESSION=tvohm-example-session; Path=/tvohm-example-path/; Secure; HttpOnly; SameSite=Lax
Minified:
IEnumerator LogInCoroutine()
{
using var request = new UnityWebRequest("https://tvohm-example-url.com/login")
{
method = UnityWebRequest.kHttpVerbPOST,
uploadHandler = new UploadHandlerRaw(UnityWebRequest.SerializeSimpleForm(new Dictionary<string, string>()
{
{ "username", "tvohm" },
{ "password", "ilovestackoverflow" }
}))
};
request.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.Success)
{
Debug.Log(request.GetResponseHeader("Set-Cookie"));
// Editor returns expected session cookie
// WebGl returns null
}
}
Invoked:
StartCoroutine(LogInCoroutine());