You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 4-WebApp-your-API/4-3-AnyOrg/Readme.md
+29-15Lines changed: 29 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -376,8 +376,8 @@ If you get errors during admin consent, consider deleting the **service princip
376
376
### Explore the sample
377
377
378
378
1. Open your browser and navigate to `https://localhost:44321` and sign-in using the link on top-right.
379
-
2. Click on Create New linkto create new tasks and you can select the user from the list and assign a task to that user.
380
-
3. Click on To-Do List to access all the tasks assigned to users in the tenant of the signed-in user.
379
+
1. Click on `To-Do List`, you can click on `Create New` link. It will redirect to create task screen where you can add a new task and assign it to any user from the list.
380
+
1. The `To-Do List` screen also displays tasks that are assigned to and created by signed-in user. The user can edit and delete the created tasks but can only view the assigned tasks.
381
381
382
382
> Did the sample not work for you as expected? Did you encounter issues trying this sample? Then please reach out to us using the [GitHub Issues](../../../../issues) page.
1. AddMicrosoftWebAppAuthentication : This enables your application to use the Microsoft identity platform endpoint. This endpoint is capable of signing-in users both with their Work and School and Microsoft Personal accounts.
403
+
1. AddMicrosoftWebAppCallsWebApi : Enables the web app to call protected APIs.
404
+
1. AddInMemoryTokenCaches: Adds an in memory token cache provider, which will cache the Access Tokens acquired for the Web API.
405
405
406
-
The following code injects the ToDoList service implementation in the client
406
+
The following code enables to add client service to use the HttpClient by dependency injection.
407
407
408
408
```CSharp
409
409
services.AddTodoListService(Configuration);
@@ -439,8 +439,9 @@ public IActionResult AdminConsentClient()
439
439
440
440
### Handle the **MsalUiRequiredException** from Web API
441
441
442
-
In `ToDoListService.cs`, the method `HandleChallengeFromWebApi` handles the `MsalUiRequiredException` response from Web API in the on-behalf of flow. It creates a consent URI and throws a custom exception i.e., `WebApiMsalUiRequiredException`.
443
-
TODO: Explain why it is needed?
442
+
If signed-in user does not have consent for a permission on the Web API, for instance "user.read.all" in this sample, then Web API will throw `MsalUiRequiredException`. The response contains the details about consent Uri and proposed action.
443
+
444
+
The Web App contains a method `HandleChallengeFromWebApi` in `ToDoListService.cs` that handles the exception thrown by API. It creates a consent URI and throws a custom exception i.e., `WebApiMsalUiRequiredException`.
The following code in `ToDoListController.cs` catches the `WebApiMsalUiRequiredException` exception and redirects to consent Uri.
477
-
478
-
TODO: Explain why it is needed?
477
+
The following code in `ToDoListController.cs` catches the `WebApiMsalUiRequiredException` exception thrown by `HandleChallengeFromWebApi` method as explained above. Further it Redirects to `consentUri` that is retrieved from exception message. Admin needs to consent as `user.read.all` permission requires admin approval.
479
478
480
479
```csharp
481
480
publicasyncTask<IActionResult>Create()
@@ -487,7 +486,6 @@ public async Task<IActionResult> Create()
487
486
}
488
487
catch (WebApiMsalUiRequiredExceptionex)
489
488
{
490
-
vara=ex.Message;
491
489
returnRedirect(ex.Message);
492
490
}
493
491
}
@@ -497,14 +495,30 @@ public async Task<IActionResult> Create()
497
495
498
496
#### Admin consent Client Redirect
499
497
500
-
In HomeController.cs, the method `AdminConsent` redirects to the URI passed in the state parameter by Web App.
498
+
In HomeController.cs, the method `AdminConsent` redirects to the URI passed in the state parameter by Web App. If admin consent is cancelled from API consent screen then it redirects to base address of Web App.
0 commit comments