musium
musium

Reputation: 3072

ASP.NET Core 3 implement IAuthorizationPolicyProvider

I’ve changed the target framework of my ASP.NET Core application from .NET Core 2.2 to 3.0.

My app contains a custom auth policy provider (IAuthorizationPolicyProvider) implementation. Since .NET Core 3 the IAuthorizationPolicyProvider interface contains a new method Task<AuthorizationPolicy> GetFallbackPolicyAsync().

What is the difference between Task<AuthorizationPolicy> GetDefaultPolicyAsync(); and Task<AuthorizationPolicy> GetFallbackPolicyAsync(). And how should GetFallbackPolicyAsync be implemented? Should it be implemented like GetDefaultPolicyAsync?

Currently my class implements the GetDefaultPolicyAsync method like this:

public CustomPolicyProvider( [NotNull] IOptions<AuthorizationOptions> options )
    => _fallbackPolicyProvider = new DefaultAuthorizationPolicyProvider( options ?? throw new ArgumentNullException( nameof(options) ) );

public Task<AuthorizationPolicy> GetDefaultPolicyAsync() => _fallbackPolicyProvider.GetDefaultPolicyAsync();

Upvotes: 10

Views: 4920

Answers (1)

RenanStr
RenanStr

Reputation: 1688

From docs for dotnet core 3.0/3.1: learn.microsoft.com

public Task<AuthorizationPolicy> GetFallbackPolicyAsync()
{
    return Task.FromResult<AuthorizationPolicy>(null);
}

Upvotes: 1

Related Questions