authentication-unity
authentication-unity copied to clipboard
WebGL support
While reviewing this package for a project that uses WebGL; I found that it works splendidly on Desktop, but when in WebGL it won't work.
After some digging, I found two main culprits: HTTPListener and HTTPClient.
HTTPListener won't work; but I managed to find a way around that by opening a popup with the authorization screen, and sending a message back to the Unity client when it returns. This was inspired by https://developer.okta.com/blog/2021/02/26/unity-webgl-playfab-authorization.
The HTTPClient bit is a bit trickier; this is used in the AuthorizationCodeFlow and UserInfoParser. And at this point I am not sure whether it could be replaced by Unity's UnityWebRequest. It would mean a change in all Clients, as they are based on the AuthorizationCodeFlow.
Have you ever got this to work? Would UnityWebRequest be a viable alternative?
Hi @mvriel ,
I was not aware of this issue. Maybe I can add an abstraction layer for http client implementation; so users can implement their http client.
Please give me some time to think about it.
Sure! I have been working on a way to make it work, perhaps you can use that as inspiration.
The following lines and files are meant as a WebGLBrowser (as opposed to the Standalone browser) to circumvent the use of HTTPListener for WebGL:
- https://github.com/Amsterdam/Netherlands3D/pull/154/files#diff-92342c546bb4b9468bf9b7515b0f7c248b7976b96b0cf4421dfd381210370027R80
- https://github.com/Amsterdam/Netherlands3D/pull/154/files#diff-b701baaeadcd453f532b8965fb349df08acdb34e768f566b2ed524ff477d0618
- https://github.com/Amsterdam/Netherlands3D/pull/154/files#diff-b9cf10b399ca5ea3d716124275a62b363bf87746f1ff2d7f22b19c439eeae022
- https://github.com/Amsterdam/Netherlands3D/pull/154/files#diff-ad3a76a4557666ee5051f0a4b23cfaa68a5a124043841ed375bcfd360648654dR17
- https://github.com/Amsterdam/Netherlands3D/pull/154/files#diff-42c8fe53669b405450984ef55deaa223a9e748a367dd9e9e5fde6f3ce01e0350
- https://github.com/Amsterdam/Netherlands3D/pull/154/files#diff-8d3ba25879bedd9baea3bbf57c5bbd4173420bfa14e66e2aa6b536cad2ef4478
- https://github.com/Amsterdam/Netherlands3D/pull/154/files#diff-e5fd58a10471ee2bac8ad0998d71bde41f043bd0b2091a6168905f9f8da04014
- https://github.com/Amsterdam/Netherlands3D/pull/154/files#diff-8dac5103c8256ed734ea7c1ef4823eb7ab70e8e485a18cff950f2247db386fb0R53
This doesn't address the HTTPClient, I am now working on an alternate AuthorizationCodeFlow that uses UnityWebRequest. Though admittedly, I am not well-versed in how CancellationTokens work; meaning that I am somewhat struggling how to reconnect the error handling and abort flow. I will probably push these changes during today
@mvriel Have you managed to implement this functionality. Are there any chances to make PR for that?