Skip to content

Commit 8ccb827

Browse files
author
Tiago Brenck
committed
Minor UI changes
1 parent 535087d commit 8ccb827

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

2-WebApp-graph-user/2-3-Multi-Tenant/Models/TodoItem.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.ComponentModel.DataAnnotations;
1+
using System.ComponentModel;
2+
using System.ComponentModel.DataAnnotations;
23
using System.ComponentModel.DataAnnotations.Schema;
34

45
namespace WebApp_OpenIDConnect_DotNet.Models
@@ -8,12 +9,18 @@ public class TodoItem
89
[Key]
910
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
1011
public int Id { get; set; }
12+
1113
[Required]
1214
public string Text { get; set; }
15+
1316
[Required]
17+
[DisplayName("User Name")]
1418
public string UserName { get; set; }
19+
1520
[Required]
21+
[DisplayName("Assigned To")]
1622
public string AssignedTo { get; set; }
23+
1724
[Required]
1825
public string TenantId { get; set; }
1926
}

2-WebApp-graph-user/2-3-Multi-Tenant/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,23 @@ The sample implements two distinct tasks: the onboarding of a new tenant and a b
168168

169169
Ideally, you would want to have two Azure AD tenants so you can test the multi-tenant aspect of this sample. For more information on how to get an Azure AD tenant, see [How to get an Azure AD tenant](https://azure.microsoft.com/documentation/articles/active-directory-howto-tenant/).
170170

171-
#### Sign-in
171+
#### Signing-in
172172

173-
Users can only sign-in if their tenant had been onboarded. The sample will guide them how to do so, but it requires a **tenant admin account** to complete the onboarding process. Once the admin have consented, all users from their tenant will be able to sign-in.
173+
Users can only sign-in if their tenant had been "onboarded". The sample will guide them how to do so, but it requires a **tenant admin account** to complete the onboarding process. Once the admin have consented, all users from their tenant will be able to sign-in.
174174

175-
If you try to sign-in for the first time without an admin account, you will be presented with the following screen. Please switch to an admin account for this step:
175+
If you try to onboard without an admin account, you will be presented with the following screen. Please switch to an admin account to complete this step:
176176

177177
![Admin Approval](ReadmeFiles/admin-approval.png)
178178

179-
If you try to sign-in with a tenant that haven't been onboarded yet, you will land in this page. Please click on **Take me to the onboarding process** button and follow the instructions to get your tenant registered in the sample database:
179+
If you try to sign-in with a tenant that haven't been "onboarded" yet, you will land in this page. Please click on **Take me to the onboarding process** button and follow the instructions to get your tenant registered in the sample database:
180180

181181
![Unauthorized Tenant](ReadmeFiles/unauthorized-tenant.png)
182182

183183
#### Todo List
184184

185185
Users from one tenant can't see todo items from other tenants. They will be able to perform basic CRUD operations on todo items assigned to them. When editing a todo item, users can assign it to any other user from their tenant. The list of users is coming from Microsoft Graph, using the [Graph SDK](https://github.com/microsoftgraph/msgraph-sdk-dotnet).
186186

187-
The list of users will be presented in the dropdown:
187+
The list of users will be presented in the **Assigned To** dropdown:
188188

189189
![Todo Edit](ReadmeFiles/todo-edit.png)
190190

@@ -217,7 +217,7 @@ Read more about [OpenID Connect endpoints here](https://docs.microsoft.com/en-us
217217

218218
### Service principle provision for new tenants (onboarding process)
219219

220-
On a multi-tenant app, its service principle will be created on all the users' tenants that have signed-in at least once. Some might want that only tenant admins accept the service principle provisioning. For that, we are using the [admin consent endpoint](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-admin-consent) for the onboarding process on the `OnboardingController.cs`. The `Onboard` action and corresponding view simulate a simple onboarding experience.
220+
On a multi-tenant app, its service principle will be created on all the users' tenants that have signed-in at least once. Some might want that only tenant admins accept the service principle provisioning. For that, we are using the [admin consent endpoint](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-admin-consent) for the onboarding process on the `OnboardingController.cs`. The `Onboard` action and corresponding view, simulate an onboarding experience.
221221

222222
```csharp
223223
[HttpPost]
@@ -238,6 +238,8 @@ public IActionResult Onboard()
238238

239239
This results in an OAuth2 code grant request that triggers the admin consent flow and creates the service principle in the admin's tenant. The `state` parameter is used to validate the response, preventing a man-in-the-middle attack. Then, the `ProcessCode` action receives the authorization code from Azure AD and, if they appear valid, it creates an entry in the application database for the new customer.
240240

241+
The `https://graph.microsoft.com/.default` is a static scope. You can find more about static scope on [this link.](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-admin-consent#request-the-permissions-from-a-directory-admin)
242+
241243
### Custom token validation allowing only registered tenants
242244

243245
On the `Startup.cs` we are calling `AddMicrosoftIdentityPlatformAuthentication` to configure the authentication, and it also validates that the token issuer is from AAD.
@@ -246,7 +248,7 @@ On the `Startup.cs` we are calling `AddMicrosoftIdentityPlatformAuthentication`
246248
options.TokenValidationParameters.IssuerValidator = AadIssuerValidator.GetIssuerValidator(options.Authority).Validate;
247249
```
248250

249-
To extend this validation to only AAD tenants registered in the application database, the event handler `OnTokenValidated` was configured to grab the `tenantId` from the token claims and check if it has on the database. If it doesn't, a custom exception `UnauthorizedTenantException` is thrown and the user is redirected to the `UnauthorizedTenant` view.
251+
To extend this validation to only Azure AD tenants registered in the application database, the event handler `OnTokenValidated` was configured to grab the `tenantId` from the token claims and check if it has an entry on the database. If it doesn't, a custom exception `UnauthorizedTenantException` is thrown, canceling the authentication, and the user is redirected to the `UnauthorizedTenant` view. At this stage, the user is not authenticated in the application.
250252

251253
```csharp
252254
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>

2-WebApp-graph-user/2-3-Multi-Tenant/Views/TodoList/Create.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<input asp-for="TenantId" class="form-control" readonly="readonly" />
3131
</div>
3232
<div class="form-group">
33-
<input type="submit" value="Create" class="btn btn-success" />
33+
<input type="submit" value="Save" class="btn btn-success" />
3434
</div>
3535
</form>
3636
</div>

2-WebApp-graph-user/2-3-Multi-Tenant/Views/TodoList/Edit.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<input type="hidden" asp-for="Id" />
3939
</div>
4040
<div class="form-group">
41-
<input type="submit" value="Edit" class="btn btn-success" />
41+
<input type="submit" value="Save" class="btn btn-success" />
4242
</div>
4343
</form>
4444
</div>

0 commit comments

Comments
 (0)