-
Notifications
You must be signed in to change notification settings - Fork 9
Authorization Scope Service
Ioan Crisan edited this page Oct 16, 2018
·
5 revisions
The authorization scope service takes an execution context and provides the authorization scope out of it. For example, if the execution context is a messaging context, it may extract from the message to be handled the entity attached to it.
It is the contract defined as shared application service. It provides a single method:
-
Task<object> GetAuthorizationScopeAsync(IContext context, CancellationToken cancellationToken = default)- context: the context to inspect.
- return value: An asynchronous result yielding the authorization scope.
Providers are services implementing the IAuthorizationScopeProvider contract, which in turn provides a single method:
-
Task<(object scope, bool canResolve)> GetAuthorizationScopeAsync(IContext context, CancellationToken cancellationToken = default)- context: the context to inspect.
- return value: An asynchronous result that yields the authorization scope and a boolean value indicating whether the resolution was successful or not.
/// <summary>
/// Default implementation of an authorization scope provider for messages.
/// </summary>
[OverridePriority(Priority.Low)]
public class MessagingAuthorizationScopeProvider : IAuthorizationScopeProvider
{
/// <summary>
/// Gets the authorization scope asynchronously.
/// </summary>
/// <param name="context">The message processing context.</param>
/// <param name="cancellationToken">Optional. the cancellation token.</param>
/// <returns>
/// An asynchronous result that yields the authorization scope.
/// </returns>
public Task<(object scope, bool canResolve)> GetAuthorizationScopeAsync(IContext context, CancellationToken cancellationToken = default)
{
if (context is IMessageProcessingContext processingContext)
{
return Task.FromResult(((object)processingContext.Message, true));
}
return Task.FromResult<(object scope, bool canResolve)>((null, false));
}
}
The default implementation of the authorization scope service aggregates the providers and calls them in the override and then processing priority to try to identify the scope. The scope returned by the first one indicating a resolution success will be returned in turn.