April 2017
Intermediate to advanced
564 pages
24h 7m
English
Custom requirements can also be implemented to handle any requirement. We can define custom requirements by implementing the IAuthorizationRequirement interface. Here is our custom requirement that only allows users if they are based in GCC countries, namely Saudi Arabia, Kuwait, United Arab Emirates, Qatar, Bahrain, and Oman:
public class BaseLocationRequirement : Microsoft.AspNetCore.Authorization.IAuthorizationRequirement { public BaseLocationRequirement(List<string> locations) { BaseLocation = locations; } public List<string> BaseLocation { get; set; } }
Once the requirement is set up, we need to define the handler that evaluates the requirement:
public class BaseLocationHandler : Microsoft.AspNetCore .Authorization.AuthorizationHandler<BaseLocationRequirement> ...Read now
Unlock full access