I am currently using the twitch api to write a bot using C# and Windows Forms. In order to get access to the current user's stream title, game, and other information, I have to send the user to twitch so that the user can log in and give my app access. This url looks something like this:
System.Diagnostics.Process.Start("https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=" + client_id + "&redirect_uri=http://localhost&scope=channel_read+channel_editor+channel_commercial+channel_subscriptions+channel_check_subscription
When the user enters their information in and presses authorize, it sends them to a link that I provided (localhost) and appends an access token onto the url. This looks something like this:
http://localhost/#access_token=[access token]&scope=channel_read+channel_editor+channel_commercial+channel_subscriptions+channel_check_subscription
Question
What is the best way to open that link, wait for the user to enter in their information, and then get the access token from the next url that they get to? This is not using ASP and this is a synchronous call. I apologize for the lack of code, I have tried multiple things and I cant seem to find anything that even comes close to working.
So after a day of messing around with it, I have found a way to get the url with the tip from Yorye Nathan.
To solve my issue, I opened the twitch authentication page with a windows form (the url with client id is passed from the main form):
public WebAuthentication(string url)
{
InitializeComponent();
webBrowser1.Navigate(url);
}
I then used a DocumentCompleted event handler to check to see if the browser has loaded the local host page. If the local host page has been loaded, the method saves the URL and then closes the form.:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (webBrowser1.Url.ToString().StartsWith("http://localhost") || webBrowser1.Url.ToString().StartsWith("https://localhost"))
{
mainForm.SetUserToken(webBrowser1.Url.ToString());
this.Hide();
}
}