System.Windows.Forms.WebBrowser
class that opens Internet Explorer on the page I need.
By the class metadata, I can use event Navigated
by passing a method that would allow me to check from the browser URL if the page I passed as redirect_url
is the one that was called (so I can get the token authentication):
public class Test
{
public void requestCode()
{
var clientId = 123; // algum clientId
var redUrl = "https://www.foo.com" // minha url de redirect
var url =
$"https://auth.mercadolivre.com.br/authorization?"+
$"response_type=code&" +
$"client_id={clientId}&"+
$"redirect_uri={redUrl}";
try
{
using (var browser = new WebBrowser())
{
browser.Navigated +=
new WebBrowserNavigatedEventHandler(
requestAuthorizeOnNavigated
);
browser.Navigate(url, Guid.NewGuid().ToString());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public void requestAuthorizeOnNavigated(
object sender,
WebBrowserNavigatedEventArgs e
)
{
Console.Write(sender.ToString(), e.ToString());
}
}
When I run my code, I can open the free market page that generates the token (or that prompts the user to authorize it initially). The problem is that I am not able to detect the navigation, even declaring the event within the using ...
What do I need to do to be able to detect the navigation (and read the URI that was informed in the last navigation) from this example?