unoplatform / uno

Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
https://platform.uno
Apache License 2.0
8.75k stars 706 forks source link

[WASM] Support for the `WebView` #329

Open jeromelaban opened 5 years ago

jeromelaban commented 5 years ago

I'm submitting a...

Expected behavior

A functional WebView control.

Affected platform(s):

jeromelaban commented 5 years ago

Here's an investigation branch: https://github.com/nventive/Uno/tree/dev/jela/webview-wasm

ToddGlodek commented 3 years ago

The business requirement for which I am investigating Uno is to extract data from a 3rd party API which will then be displayed inside Uno. Access to the 3rd party API is user specific - each user is authenticated by a two-factor OATH2 access mechanism which returns an access token for that specific user. The 3rd party authentication mechanism was designed to be called by a web browser navigating to that API's site where the the authentication would occur; and then redirecting the browser back to our own website with a cookie that contains the access token. The 3rd party API cannot be accessed except by using the token - which expires every 24 hours. When the token expires, each user must repeat the authentication process to obtain a new token.

I had implemented this mechanism previously in Xamarin Forms using the technique of embedding a WebView on a Forms Page - which I could use to gain access to the cookie/token. Well, maybe I am doing it all wrong, but I thought I could reuse that technique because has the benefit of not needing to exit the app to reauthenticate if the token expires in the middle of a session.

An alternative would be to host the Uno/WASM app on a page within our website and then pass the access token to app after authentication had already occurred. This is similar to way Silverlight/Moonlight apps were implemented; but it wasn't clear from the Uno sample application how to host an Uno app inside an existing ASP.Net MVC website. Moreover, if the token expires mid-session, the app must be exited, re-authentication performed, and then the app restarted. Should this occur, there is the problem of what to do with the unsaved work-in-progress when you exit the app because there is no way to save it back to the API with an expired token.

This is the determining factor in our ability to use the UnoPlatform.

Your guidance is greatly appreciated.

jeromelaban commented 3 years ago

Thanks for the update. In this case, the immediate solution would be to invoke some Javascript that would the same process that you would do on a standard Javascript app. If you have such a piece of code, you can reuse it in an Uno application.

ToddGlodek commented 3 years ago

Not possible... the OAUTH2.0 Authorization Code Flow requires :

Here's a quick video that helps to visualize the process

As is indicated in the Authorization Code Flow above, there are different approaches required for:

Because of the varying security concerns inherent to the various platforms (browser, mobile, Windows/Apple/Linux ) -- it is not possible to have a single cross platform strategy that handles OAUTH2,0 authentication in exactly the same way the. Does UnoPlatform have an OAUTH2,0 ticket open. If not should I create one ?

jeromelaban commented 3 years ago

OAuth 2 is definitely possible in browsers, and SPAs, as you'd find in the use of MSAL.NET, for instance. In general, any javascript library that is SPA compatible will work with Uno with some javascript interop.

Also, there's https://github.com/unoplatform/uno/issues/3393 opened for a more general OpenID support.

kaki104 commented 3 years ago

Is it possible to use WebView control in WASM project?

davidjohnoliver commented 3 years ago

Is it possible to use WebView control in WASM project?

At the moment WebView is not supported, that's what this issue is tracking. Please upvote it if it's something you'd like to see.

For workarounds, you can look at this SO question, or else the implementation for a login page frame in the UADO reference app.