IdentityServer4.Admin icon indicating copy to clipboard operation
IdentityServer4.Admin copied to clipboard

How to validate client has permission to access specific api?

Open ajaypunekar1 opened this issue 4 years ago • 2 comments

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)
	{
	}
}

ajaypunekar1 avatar Dec 08 '21 08:12 ajaypunekar1

https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-protected-web-api-verification-scope-app-roles?tabs=aspnetcore

This can help you.

ekjuanrejon avatar Jan 01 '22 07:01 ekjuanrejon

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.

ajaypunekar1 avatar Jan 03 '22 05:01 ajaypunekar1