Skip to content

Services IAuthorizationCodeFailureNotifier

Mika Berglund edited this page Dec 25, 2025 · 2 revisions

Authorization Code Failure Notifier (IAuthorizationCodeFailureNotifier)

The Authorization Code Failure Notifier handles failures that occur when requesting an authorization code and exposes those failures to application code through an event.

This service is meant for surfacing failures, for example by displaying an error to the user, logging, or triggering telemetry. It does not attempt to retry, recover, or translate the failure into a different model.

Responsibilities

  • Accept an authorization code failure result.
  • Notify subscribers that an authorization code request has failed.
  • Provide an overridable hook for customizing how failure notifications are raised.

Members

  • Failed: Occurs when an authorization code request fails.
  • HandleFailureAsync: When called, handles the specified authorization code failure result.

Default implementation

The default implementation is AuthorizationCodeFailureNotifier.

It implements the Failed event using an internal event handler field and raises the event whenever HandleFailureAsync is called. The method returns Task.CompletedTask after raising the event.

A protected virtual OnFailed method is used to raise the event. Deriving from the default implementation and overriding OnFailed is the intended customization point if you need additional behavior, such as logging or telemetry, before or after notifying subscribers.

Usage

Subscribe to failures

  • Subscribe to Failed to be notified when an authorization code request does not succeed.
  • The event provides failure details through the AuthorizationCodeResult argument.

Publish a failure

  • Call HandleFailureAsync with the AuthorizationCodeResult that represents the failure.

Notes and pitfalls

  • The default implementation does not queue or persist failures. If there are no subscribers when the event is raised, the failure is effectively ignored.
  • Event handlers that throw exceptions will cause those exceptions to propagate from the event invocation. If you want isolation, override OnFailed and wrap invocation in exception handling.
  • HandleFailureAsync does not perform asynchronous work in the default implementation. If you need awaited processing, implement your own notifier or schedule asynchronous work from an overridden OnFailed.

References

Clone this wiki locally