Skip to content

Commit 7fca9c5

Browse files
author
Tiago Brenck
authored
Merge pull request #333 from Azure-Samples/tibre/addNugetReview
Readme updates for new Microsoft.Identity.Web nuget package
2 parents 1312866 + 9b3edd9 commit 7fca9c5

File tree

8 files changed

+69
-111
lines changed

8 files changed

+69
-111
lines changed

1-WebApp-OIDC/1-2-AnyOrg/README-1-1-to-1-2.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@ In the `Startup.cs` file, in the `ConfigureServices` method, after `services.Add
6464
{
6565
...
6666
// Sign-in users with the Microsoft identity platform
67-
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
68-
.AddSignIn("AzureAd", Configuration, options => Configuration.Bind("AzureAd", options));
69-
70-
// Restrict users to specific belonging to specific tenants
71-
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
67+
services.AddSignIn(Configuration, options =>
7268
{
69+
Configuration.Bind("AzureAd", options);
70+
// Restrict users to specific belonging to specific tenants
7371
options.TokenValidationParameters.IssuerValidator = ValidateSpecificIssuers;
74-
});
72+
}, options => Configuration.Bind("AzureAd", options));
7573
...
7674
```
7775

1-WebApp-OIDC/1-3-AnyOrgOrPersonal/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ There is one project in this sample. To register it, you can:
4343
3. Run the following script to create and configure your Azure AD application and configure the code of the sample application as well.
4444
4545
```PowerShell
46-
cd .\AppCreationScripts\
47-
.\Configure.ps1
46+
cd .\AppCreationScripts\
47+
.\Configure.ps1
4848
```
4949
5050
> Other ways of running the scripts are described in [App Creation Scripts](./AppCreationScripts/AppCreationScripts.md)

1-WebApp-OIDC/1-5-B2C/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ Your web application registration should include the following information:
8383
"Instance": "https://<your-tenant-name>.b2clogin.com",
8484
"ClientId": "<web-app-application-id>",
8585
"Domain": "<your-b2c-domain>",
86-
"CallbackPath": "/signin/B2C_1_sign_up_in",
87-
"SignedOutCallbackPath": "/signout/B2C_1_sign_up_in",
86+
"SignedOutCallbackPath": "/signout/<your-sign-up-in-policy>",
8887
"SignUpSignInPolicyId": "<your-sign-up-in-policy>"
8988
}
9089
}
@@ -112,16 +111,16 @@ If your web site needs to be accessed from users using iOS 12, you probably want
112111
This sample does NOT use MSAL as it only signs-in users (it does not call a Web API). It uses the built-in ASP.NET Core middleware. MSAL is used for fetching access for accessing protected APIs (not shown here), as well as ID tokens. For logging-in purposes, it is sufficient to obtain an ID Token, and the middleware is capable of doing this on its own.
113112

114113
#### Where is the Account controller?
115-
The `AccountController.cs` used in this sample is part of the built-in .NET Core authentication controllers found in the NuGet package `Microsoft.AspNetCore.Authentication.AzureADB2C.UI`, and you can find its implementation [here](https://github.com/aspnet/AspNetCore/blob/master/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/Areas/AzureADB2C/Controllers/AccountController.cs). If you want to customize the **Sign-in**, **Sign-up** or **Sign-out** actions, you are encouraged to create your own controller.
114+
The `AccountController.cs` used in this sample is part of `Microsoft.Identity.Web.UI` NuGet package, and you can find its implementation [here](https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web.UI/Areas/MicrosoftIdentity/Controllers/AccountController.cs). If you want to customize the **Sign-in**, **Sign-up** or **Sign-out** actions, you are encouraged to create your own controller.
116115

117116
#### B2C middlerware
118-
This sample shows how to use the OpenID Connect ASP.NET Core middleware to sign in users from a single Azure AD B2C tenant. The middleware is initialized in the `Startup.cs` file by passing the default authentication scheme and `AzureADB2COptions.cs` options. The options are read from the `appsettings.json` file. The middleware takes care of:
117+
This sample shows how to use the OpenID Connect ASP.NET Core middleware to sign in users from a single Azure AD B2C tenant. The middleware is initialized in the `Startup.cs` file by passing the default authentication scheme and `OpenIdConnectOptions.cs` options. The options are read from the `appsettings.json` file. The middleware takes care of:
119118

120119
- Requesting OpenID Connect sign-in using the policy from the `appsettings.json` file.
121120
- Processing OpenID Connect sign-in responses by validating the signature and issuer in an incoming JWT, extracting the user's claims, and putting the claims in `ClaimsPrincipal.Current`.
122121
- Integrating with the session cookie ASP.NET Core middleware to establish a session for the user.
123122

124-
You can trigger the middleware to send an OpenID Connect sign-in request by decorating a class or method with the `[Authorize]` attribute or by issuing a challenge (see the [AccountController.cs](https://github.com/aspnet/AspNetCore/blob/master/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/Areas/AzureADB2C/Controllers/AccountController.cs) file which is part of ASP.NET Core).
123+
You can trigger the middleware to send an OpenID Connect sign-in request by decorating a class or method with the `[Authorize]` attribute or by issuing a challenge (see the [AccountController.cs](https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web.UI/Areas/MicrosoftIdentity/Controllers/AccountController.cs) file).
125124

126125
Here is the middleware example:
127126

1-WebApp-OIDC/1-6-SignOut/README.md

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,21 @@ The sign out button is exposed in `Views\Shared\_LoginPartial.cshtml` and only d
2828
{
2929
<ul class="nav navbar-nav navbar-right">
3030
<li class="navbar-text">Hello @User.GetDisplayName()!</li>
31-
<li><a asp-area="AzureAD" asp-controller="Account" asp-action="SignOut">Sign out</a></li>
31+
<li><a asp-area="MicrosoftIdentity" asp-controller="Account" asp-action="SignOut">Sign out</a></li>
3232
</ul>
3333
}
3434
else
3535
{
3636
<ul class="nav navbar-nav navbar-right">
37-
<li><a asp-area="AzureAD" asp-controller="Account" asp-action="SignIn">Sign in</a></li>
37+
<li><a asp-area="MicrosoftIdentity" asp-controller="Account" asp-action="SignIn">Sign in</a></li>
3838
</ul>
3939
}
4040
```
4141

4242
### `Signout()` action of the `AccountController`
4343

44-
Pressing the **Sign out** button on the web app, triggers the `SignOut` action on the `Account` controller. In previous versions of the ASP.NET core templates, this controller
45-
was embedded with the Web App, but this is no longer the case as it's now part of the ASP.NET Core framework itself. The code for the `AccountController` is available from the ASP.NET core repository at
46-
from <https://github.com/aspnet/AspNetCore/blob/master/src/Azure/AzureAD/Authentication.AzureAD.UI/src/Areas/AzureAD/Controllers/AccountController.cs>, and what it does is:
44+
Pressing the **Sign out** button on the web app, triggers the `SignOut` action on the `Account` controller. The code for the `AccountController` is available at [Microsoft.Identity.Web repository]
45+
(https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web.UI/Areas/MicrosoftIdentity/Controllers/AccountController.cs), and what it does is:
4746

4847
- set an openid redirect URI to `/Account/SignedOut` so that the controller is called back when Azure AD has performed the sign out
4948
- call `Signout()`, which lets the OpenId connect middleware contact the Microsoft identity platform `logout` endpoint which:
@@ -56,44 +55,18 @@ from <https://github.com/aspnet/AspNetCore/blob/master/src/Azure/AzureAD/Authent
5655
The ASP.NET Core OpenIdConnect middleware enables your app to intercept the call to the Microsoft identity platform logout endpoint by providing an OpenIdConnect event named `OnRedirectToIdentityProviderForSignOut`.
5756

5857
```CSharp
59-
public static IServiceCollection AddSignIn(this IServiceCollection services,
60-
IConfiguration configuration)
58+
services.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
6159
{
62-
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
60+
options.Events.OnRedirectToIdentityProviderForSignOut = async context =>
6361
{
64-
options.Authority = options.Authority + "/v2.0/";
65-
66-
options.Events.OnRedirectToIdentityProviderForSignOut = async context =>
67-
{
68-
//Your logic here
69-
};
70-
}
71-
}
62+
//Your logic here
63+
};
64+
});
7265
```
7366

7467
### Clearing the token cache
7568

76-
Your application can also intercept the logout event, for instance to clear the entry of the token cache associated with the account that signed out. We'll see in the second part of this tutorial (about the Web app calling a Web API), that the web app will store access tokens for the user in a cache. Intercepting the logout callback enables your web application to remove the user from the token cache. This is illustrated in the `AddWebAppCallsProtectedWebApi()` method of [StartupHelper.cs L137-143](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/b87a1d859ff9f9a4a98eb7b701e6a1128d802ec5/Microsoft.Identity.Web/StartupHelpers.cs#L137-L143)
77-
78-
```CSharp
79-
public static IServiceCollection AddWebAppCallsProtectedWebApi(this IServiceCollection services, IEnumerable<string> initialScopes)
80-
{
81-
services.AddTokenAcquisition();
82-
83-
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
84-
{
85-
...
86-
// Handling the sign-out: removing the account from MSAL.NET cache
87-
options.Events.OnRedirectToIdentityProviderForSignOut = async context =>
88-
{
89-
// Remove the account from MSAL.NET token cache
90-
var _tokenAcquisition = context.HttpContext.RequestServices.GetRequiredService<ITokenAcquisition>();
91-
await _tokenAcquisition.RemoveAccount(context);
92-
};
93-
});
94-
return services;
95-
}
96-
```
69+
Your application can also intercept the logout event, for instance to clear the entry of the token cache associated with the account that signed out. We'll see in the second part of this tutorial (about the Web app calling a Web API), that the web app will store access tokens for the user in a cache. Intercepting the logout callback enables your web application to remove the user from the token cache. This is illustrated in the `AddWebAppCallsProtectedWebApi()` method of [WebAppServiceCollectionExtensions.cs](https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web/WebAppServiceCollectionExtensions.cs#L202-L208)
9770

9871
### Single Sign-Out
9972

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The application puts forward a scenario where a SaaS application invites the adm
5656

5757
To run this sample:
5858

59-
> Pre-requisites: Install .NET Core 2.2 or later (for example for Windows) by following the instructions at [.NET and C# - Get Started in 10 Minutes](https://www.microsoft.com/net/core). In addition to developing on Windows, you can develop on [Linux](https://www.microsoft.com/net/core#linuxredhat), [Mac](https://www.microsoft.com/net/core#macos), or [Docker](https://www.microsoft.com/net/core#dockercmd).
59+
> Pre-requisites: Install .NET Core 3.1 or later (for example for Windows) by following the instructions at [.NET and C# - Get Started in 10 Minutes](https://www.microsoft.com/net/core). In addition to developing on Windows, you can develop on [Linux](https://www.microsoft.com/net/core#linuxredhat), [Mac](https://www.microsoft.com/net/core#macos), or [Docker](https://www.microsoft.com/net/core#dockercmd).
6060
6161
Ideally, you would want to have two Azure AD tenants so you can test all the aspects of this multi-tenant 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/).
6262

@@ -210,8 +210,7 @@ These steps are encapsulated in the [Microsoft.Identity.Web](..\..\Microsoft.Ide
210210
In order to be able to sign-in users from multiple tenants, the [/common endpoint](https://docs.microsoft.com/azure/active-directory/develop/howto-convert-app-to-be-multi-tenant#update-your-code-to-send-requests-to-common) must be used. In the sample, this endpoint is used as a result of setting the value for `TenantId` as `organizations` on the `appsettings.json` file, and configuring the middleware to read the values from it.
211211

212212
```csharp
213-
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
214-
.AddAzureAD(options => configuration.Bind(configSectionName, options));
213+
services.AddSignIn(Configuration);
215214
```
216215

217216
You can read about the various endpoints of the Microsoft Identity Platform [here](https://docs.microsoft.com/azure/active-directory/develop/active-directory-v2-protocols#endpoints).
@@ -256,7 +255,7 @@ options.TokenValidationParameters.IssuerValidator = AadIssuerValidator.GetIssuer
256255
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.
257256

258257
```csharp
259-
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
258+
services.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
260259
{
261260
options.Events.OnTokenValidated = async context =>
262261
{
@@ -296,7 +295,7 @@ If you want to read more about data architecture on multi-tenant apps, please re
296295

297296
### Acquiring Access token for Microsoft Graph for each tenant
298297

299-
If a multi-tenant app needs to acquire an access token for Microsoft Graph to be able to read data from the signed user's tenant, the token must be issued from their tenanted authority and not from the tenant where the SaaS application is registered. This feature is being showed on the **Edit** action result on `todoListController.cs`.
298+
If a multi-tenant app needs to acquire an access token for Microsoft Graph to be able to read data from the signed user's tenant, the token must be issued from their tenanted authority and not from the tenant where the SaaS application is registered. This feature is being showed on the **Edit** action result on `TodoListController.cs`.
300299

301300
```csharp
302301
var userTenant = User.GetTenantId();

4-WebApp-your-API/4-1-MyOrg/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ As a first step you'll need to:
123123
- Select **Add a scope**
124124
- accept the proposed Application ID URI (api://{clientId}) by selecting **Save and Continue**
125125
- Enter the following parameters
126-
- for **Scope name** use `user_impersonation`
126+
- for **Scope name** use `access_as_user`
127127
- Keep **Admins and users** for **Who can consent**
128128
- in **Admin consent display name** type `Access TodoListService-aspnetcore-webapi as a user`
129129
- in **Admin consent description** type `Accesses the TodoListService-aspnetcore-webapi Web API as a user`
@@ -189,7 +189,7 @@ Note: if you had used the automation to setup your application mentioned in [Ste
189189
1. Find the app key `TenantId` and replace the existing value with your Azure AD tenant ID.
190190
1. Find the app key `ClientId` and replace the existing value with the application ID (clientId) of the `TodoListClient-aspnetcore-webapi` application copied from the Azure portal.
191191
1. Find the app key `ClientSecret` and replace the existing value with the key you saved during the creation of the `TodoListClient-aspnetcore-webapi` app, in the Azure portal.
192-
1. Find the app key `TodoListScope` and replace the existing value with Scope if you changed the name from `api://<client id>/user_impersonation`.
192+
1. Find the app key `TodoListScope` and replace the existing value with Scope if you changed the name from `api://<client id>/access_as_user`.
193193
1. Find the app key `TodoListBaseAddress` and replace the existing value with the base address of the TodoListService-aspnetcore-webapi project (or use the default `https://localhost:44351`).
194194

195195
### Step 4: Run the sample
@@ -205,7 +205,7 @@ This behavior is expected as you are not authenticated. The client application w
205205

206206
Explore the sample by signing in into the TodoList client, adding items to the To Do list. If you stop the application without signing out, the next time you run the application, you won't be prompted to sign in again.
207207

208-
NOTE: Remember, the To-Do list is stored in memory in this `TodoListService` app. Each time you run the projects, your To-Do list will get emptied.
208+
> NOTE: Remember, the To-Do list is stored in memory in this `TodoListService` app. Each time you run the projects, your To-Do list will get emptied.
209209
210210
> 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.
211211

0 commit comments

Comments
 (0)