using angular .net sample for msal, how to make controllers accessbile only when there is an authenticated session

Miguel 280 Reputation points
2023-05-04T01:10:36.3866667+00:00

this is the link for msal sample of the documentation,thx

https://github.com/Azure-Samples/ms-identity-javascript-angular-tutorial/tree/main/3-Authorization-II/2-call-api-b2c

I also use this in my custom policies

 
Microsoft Security Microsoft Entra Microsoft Entra External ID
{count} votes

Accepted answer
  1. Akshay-MSFT 17,951 Reputation points Microsoft Employee Moderator
    2023-05-10T04:25:06.9433333+00:00

    @Miguel

    Thank you for posting your time and patience on this. To make controller accessible you could define the scopes as per https://github.com/Azure-Samples/ms-identity-javascript-angular-tutorial/blob/main/3-Authorization-II/2-call-api-b2c/API/TodoListAPI/Controllers/TodoListController.cs

    User's image

    • The scopes if the API is called on behalf of a user.
    • The app roles if the API can be called from a daemon app.

    You can verify the scopes in the controller action by using the [RequiredScope] attribute. This attribute has several overrides. One that takes the required scopes directly, and one that takes a key to the configuration.

    Please do let me know if you have any queries in the comments section.

    Thanks,

    Akshay Kaushik

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.