0
Hello, I’m doing an integration with the Free Market API, where I need to open a browser screen with the page for the user to allow access to my application’s API (as the documentation here). To do this, I intend to take advantage of the class System.Windows.Forms.WebBrowser
that opens Internet Explorer on the page I need.
By the class master, I can use the event Navigated
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 authentication token) so:
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 asks the user to authorize initially). The problem is that I’m not managing to detect navigation, even declaring the event within using...
What I need to do to be able to detect browsing (and read the URI that was reported in the last navigation) from this example?
If you use the event
DocumentCompleted
can get the URL from the parametere
who’s kindWebBrowserDocumentCompletedEventArgs
.– João Martins
I’ll see if I can use it this way... Thank you
– LeandroLuk