Esempio n. 1
0
        protected virtual void OnAuthChanged(OAuthEvent e)
        {
            this.OAuthToken = e.OAuth;

            // do callback
            if (_on_oauth_changed != null)
            {
                _on_oauth_changed.Invoke(this, e);
            }
        }
Esempio n. 2
0
        private void TwitchBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            // check to see if we at the callback URL stage
            if (e.Url.AbsoluteUri.StartsWith(this.TwitchCallbackUri.OriginalString))
            {
                // check the callback #
                int sharp_index = e.Url.AbsoluteUri.IndexOf('#', this.TwitchCallbackUri.OriginalString.Length);

                // got the # location
                if (sharp_index >= 0)
                {
                    // parse the query string
                    string query = e.Url.AbsoluteUri.Substring(sharp_index + 1);

                    // get all the options from the query string
                    var options = HttpUtility.ParseQueryString(query);

                    // check to see if we have the access_token & scope
                    if (options.AllKeys.Contains("access_token") &&
                        options.AllKeys.Contains("scope"))
                    {
                        // create the event
                        OAuthEvent oae = new OAuthEvent();
                        oae.StatusCode = OAuthStatusCode.AUTHENTICATED;
                        oae.OAuth      = options["access_token"];

                        // add each scope option
                        string[] scope_options = options["scope"].Split('+');
                        foreach (string scope_option in scope_options)
                        {
                            oae.Scope.Add(scope_option);
                        }

                        // fire the event
                        OnAuthChanged(oae);

                        // clean up
                        this.Hide();
                    }
                }
                else
                {
                    // they cancel the OAuth process by click "cancel" or an error has happen
                    // create the event (error)
                    OAuthEvent oae     = new OAuthEvent();
                    var        options = HttpUtility.ParseQueryString(e.Url.Query);

                    // assume canceled
                    oae.StatusCode = OAuthStatusCode.CANCELED;

                    // check for other error codes
                    if (options.AllKeys.Contains("error"))
                    {
                        if (options["error"] == "redirect_mismatch")
                        {
                            oae.StatusCode    = OAuthStatusCode.CALLBACK_URL_MISMATCH;
                            oae.StatusMessage = options["error_description"].Replace('+', ' ');
                        }
                    }

                    this.Hide();
                }
            }
            else if (e.Url.AbsoluteUri.StartsWith("https://api.twitch.tv/"))
            {
                this.Show();
            }
        }