How to validate client has permission to access specific api?
I have two apis which perform different task. I want to validate client has permission to access the api when user grant(on consent page) the permission.
Calender api
1: calender.read 2: calender.write
I have Client1(with only calender.read permission) and Client2(with both permission). So on api level how can I validate this permission? Please check below api controller.
[Route("api/[controller]")]
[ApiController]
[TypeFilter(typeof(ControllerExceptionFilterAttribute))]
[Produces("application/json", "application/problem+json")]
[Authorize]
public class CalenderController : ControllerBase
{
/// <summary>
/// fetch user calender data
/// Note: You can fetch max last one year data.
/// </summary>
/// <param name="fromDate">epoch utc date stamp in seconds</param>
/// <param name="toDate">epoch utc date stamp in seconds.</param>
/// <param name="page"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
[HttpGet]//calender.read
public async Task<ActionResult<CalenderApiDto>> Get(double fromDate, double toDate, int page = 1, int pageSize = 10)
{
//.... some code
}
[HttpPost]//calender.write
[ProducesResponseType(201)]
[ProducesResponseType(400)]
public async Task<ActionResult<TUserCalDto>> Post([FromBody]TUserCalDto user)
{
}
}
https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-protected-web-api-verification-scope-app-roles?tabs=aspnetcore
This can help you.
https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-protected-web-api-verification-scope-app-roles?tabs=aspnetcore
This can help you.
Thanks :) Will try this.