tryphotino / photino.NET

https://tryphotino.io
Apache License 2.0
833 stars 68 forks source link

Can I intercept navigation events? #139

Open vpopescu opened 1 year ago

vpopescu commented 1 year ago

I am trying to see if I can use this library to implement OAUTH in my dotnet application. In order to accomplish this, I need to be able to intercept the redirect responses from the server, because I need to compare them against the OAUTH callback value.

Is there a way to register for events for when the url changes in the browser? Basically the "Navigation Starting" event from WebView2 (https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/navigation-events)

I did notice a WebMessageReceivedHandler available, but (at least on windows) I can't get it to fire to understand what it does. (EDIT: I now understand this event appears to fire only when something clicked, so it won't help me).

ottodobretsberger commented 1 year ago

We do not currently handle those kind of events (yet). These events would need to be added to the list of events we already do handle, which someone with time and interest could probably accomplish. It is not going to be on our immediate TODO list though.

rtmann commented 9 months ago

You can do this, but not using the built in c#/js interop. You need to build a proper webapi and then self host it in the Photino app.

But that's cool, because you can then use all the webapi packages for OAuth.

You don't have to self host it though, you would just be keeping state in w/e is hosting the api.

MikeYeager commented 9 months ago

If you want to handle the navigation events on the client, that can be done in JavaScript. It's built into many SPA frameworks. Or in pure JavaScript, take a look at https://developer.mozilla.org/en-US/docs/Web/API/Navigation/navigate_event#examples. If you want to handle it on the back end, then @rtmann is correct, you can handle it in the web server. ASP.NET for example, which is small, fast and already included in the deployment. the only place you can't handle it right now is in the WebView control where it raises an event sent back to your .NET app. We may be able to add that at some point.

rtmann commented 9 months ago

Yeah, I guess my point was that if you use the web api on the back end, you don't need to handle any navigation events. The packages, configured properly, will just work.