I'm writing a C# application that requests Facebook authentication from the user.
To this end, I have created a WebBrowser control, and navigate to "https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=https://www.facebook.com/connect/login_success.html". This shows the authorization window to the user. When the user clicks Allow, the browser is redirected (via HTTP 302) to "https://www.facebook.com/connect/login_success.html?code=ACCESS_CODE". However, when the WebBrowser control is redirected to this URL, it disappears from its parent form and pops up in a new Internet Explorer window.
Why is this happening, and how can I fix it?
Relevant code:
public bool getAuthCode()
{
Form f = new Form();
WebBrowser wb = new WebBrowser();
WebBrowserDocumentCompletedEventHandler handle = new WebBrowserDocumentCompletedEventHandler(wb_urlChange_Handler);
wb.DocumentCompleted += handle;
wb.Dock = DockStyle.Fill;
f.Text = "Authenticate App";
f.Size = new System.Drawing.Size(1000, 600);
f.Controls.Add(wb);
wb.Navigate(new System.Uri(this.generateAuthCodeURL()));
f.ShowDialog();
f.Dispose();
return true;
}
private void wb_urlChange_Handler(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (handleAuthCodeURL(e.Url.ToString()))
{
WebBrowser wb = (WebBrowser)sender;
wb.Dispose();
((Form)wb.Parent).Close();
}
}