/// <summary> /// /// Factory method for creating an object for a failed flow. /// </summary> /// <param name="errorType">The type of error</param> /// <param name="errorMessage">The error details</param> /// <returns>The instance containing the error type and details</returns> public static AuthorizationEventArgs Error(string errorType, string errorMessage) { AuthorizationEventArgs args = new AuthorizationEventArgs(); args.ErrorType = errorType; args.ErrorMessage = errorMessage; args.IsSuccessful = false; return args; }
/// <summary> /// Event handler for the authorization flow finished event. /// In this showcase only the result is printed, ideally you would save the token (or handle the error), /// and sign all future requests with it. /// </summary> /// <param name="sender">The sender of the event (not used)</param> /// <param name="e">The event arguments containing the details (error message, token, etc.)</param> private void WinFormsSSOManager_AuthorizationFinished(object sender, AuthorizationEventArgs e) { browser.Navigate("about:blank"); if (e.IsSuccessful) { result.Text = "SUCCESS - token is " + e.Token; } else { result.Text = "ERROR: " + e.ErrorType + " - " + e.ErrorMessage; } }
/// <summary> /// Factory method for creating an object for a successful flow. /// </summary> /// <param name="authToken">The OAuth2 access token</param> /// <returns>The instance containing the access token</returns> public static AuthorizationEventArgs Success(string authToken) { AuthorizationEventArgs args = new AuthorizationEventArgs(); args.Token = authToken; args.IsSuccessful = true; return args; }
/// <summary> /// Internal method for emitting the event from a platform-specific SSO manager at the end of the flow. /// </summary> /// <param name="args">The arguments containing the result</param> protected static void OnAuthorizationFinished(AuthorizationEventArgs args) { AuthorizationEventHandler handler = AuthorizationFinished; if (handler != null) { // Emits the event handler(null, args); } }