/// <summary> /// Verifies validity of the hash response from the host. If the response is valid /// then <see cref="TwitchAuthenticated"/> is raised. /// </summary> /// <param name="hash">The parsed hash data.</param> public void SubmitTwitchVerification(TwitchHashFile hash) { if (this.AwaitingPlatform != SocialPlatform.Twitch) { // Decline the request to submit this fragment since we're not waiting for it. return; } var hostState = this.State.Trim().ToLower(); var hostNonce = this.Nonce.Trim().ToLower(); var clientState = hash.State.Trim().ToLower(); var clientNonce = hash.Fragment.Nonce.Trim().ToLower(); if (!hostState.Equals(clientState) || !hostNonce.Equals(clientNonce)) { MessageBox.Show( "An invalid response was received at our endpoint.\n" + "It is possible a third party is attempting to get access to your authenticated token.\n" + "Due to the risk of this possiblity, we are forcing the application to crash.\n" + "This will generate new state tokens for verification.\n\n", "There was a critical exception."); Application.Exit(); } else { // we've verified the response to have valid state and nonce // thus we should update with the fragment and close the form. this.TwitchAuthenticated?.Invoke(this, new TwitchAuthenticatedEventArgs(hash)); this.Close(); } }
private void SubmitTwitchVerification(TwitchHashFile hash) { if (this.AwaitingPlatform != SocialPlatform.Twitch) { // Decline the request to submit this fragment since we're not waiting for it. return; } var hostState = this.State.Trim().ToLower(); var hostNonce = this.Nonce.Trim().ToLower(); var clientState = hash.State.Trim().ToLower(); var clientNonce = hash.Fragment.Nonce.Trim().ToLower(); if (!hostState.Equals(clientState) || !hostNonce.Equals(clientNonce)) { MessageBox.Show( "An invalid response was received at our endpoint.\n" + "It is possible a third party is attempting to get access to your authenticated token.\n" + "Due to the risk of this possiblity, we are forcing the application to crash.\n" + "This will generate new state tokens for verification.\n\n", "There was a critical exception."); Application.Exit(); } else { this.altAccountLabel.Visible = true; this.altAccountNameLabel.Visible = true; this.altAccountNameLabel.Text = Utility.GetDisplayNameFromID(this.context.API, hash.Fragment.Subject); this.context.AlterChatbot(this.altAccountNameLabel.Text, hash.AccessToken); Settings.Save(altTwitchSubject: hash.Fragment.Subject, altTwitchAccessToken: hash.AccessToken); } }
public TwitchAuthenticatedEventArgs(TwitchHashFile hash) { this.Hash = hash; }