Skip to content

Commit db56d5a

Browse files
author
Tiago Brenck
committed
Merge branch 'master' into tibre/multiTenantSample
2 parents e93616b + 5fc5e04 commit db56d5a

22 files changed

+60
-453
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,6 @@
101101
/2-WebApp-graph-user/2-4-Sovereign-Call-MSGraph/bin/Release/netcoreapp2.2
102102
/Microsoft.Identity.Web.Test/bin/Release/netcoreapp2.2
103103
/Microsoft.Identity.Web.Test/obj
104+
/4-WebApp-your-API/4-2-B2C/.vs
105+
/4-WebApp-your-API/4-2-B2C/Client/obj
106+
/4-WebApp-your-API/4-2-B2C/TodoListService/obj

2-WebApp-graph-user/2-2-TokenCache/Startup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public void ConfigureServices(IServiceCollection services)
5151
// and chosen token cache implementation
5252
services.AddMicrosoftIdentityPlatformAuthentication(Configuration)
5353
.AddMsal(Configuration, new string[] { Constants.ScopeUserRead })
54-
.AddSqlAppTokenCache(msalSqlTokenCacheOptions)
55-
.AddSqlPerUserTokenCache(msalSqlTokenCacheOptions);
54+
.AddSqlTokenCaches(msalSqlTokenCacheOptions);
5655

5756

5857
// Add Graph

3-WebApp-multi-APIs/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ insert
189189

190190
## Troubleshooting
191191

192+
To access Azure Resource Management (ARM), you'll need a work or school account (AAD account) and an Azure subscription. If your Azure subscription is for a Microsoft personal account, just create a new user in your directory, and use this user to run the sample
193+
192194
OpenIdConnectProtocolException: Message contains error: 'invalid_client', error_description: 'AADSTS650052: The app needs access to a service (\"https://*.blob.core.windows.net\") that your organization \"*tenantname*.onmicrosoft.com\" has not subscribed to or enabled. Contact your IT Admin to review the configuration of your service subscriptions.
193195
this is because the AzureStorage API was not registered as an API used by your Web App
194196

@@ -198,4 +200,4 @@ You can learn more about the tokens by looking at the following articles in MSAL
198200

199201
- The [Authorization code flow](https://aka.ms/msal-net-authorization-code), which is used, after the user signed-in with Open ID Connect, in order to get a token and cache it for a later use. See [TokenAcquisition L 107](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/f99e913cc032e16c59b748241111e97108e87918/Extensions/TokenAcquisition.cs#L107) for details of this code
200202
- [AcquireTokenSilent](https://aka.ms/msal-net-acquiretokensilent ), which is used by the controller to get an access token for the downstream API. See [TokenAcquisition L 168](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/f99e913cc032e16c59b748241111e97108e87918/Extensions/TokenAcquisition.cs#L168) for details of this code
201-
- [Token cache serialization](msal-net-token-cache-serialization)
203+
- [Token cache serialization](msal-net-token-cache-serialization)

4-WebApp-your-API/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ In the left-hand navigation pane, select the **Azure Active Directory** service,
417417
> NOTE: Remember, the To Do list is stored in memory in this TodoListService sample. Azure Web Sites will spin down your web site if it is inactive, and your To Do list will get emptied.
418418
Also, if you increase the instance count of the web site, requests will be distributed among the instances. To Do will, therefore, not be the same on each instance.
419419
420+
## Next steps
421+
422+
If you're interested in the Web API calling a downstream API, you might want to have a look at the [ASP.NET Core Web API tutorial](https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore-v2), in chapter 2 [2. Web API now calls Microsoft Graph/](https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore-v2/tree/master/2.%20Web%20API%20now%20calls%20Microsoft%20Graph). The client is a desktop app there, whereas you have a Web App, but apart from that all the app registration steps apply.
423+
420424
## Community Help and Support
421425
422426
Use [Stack Overflow](http://stackoverflow.com/questions/tagged/msal) to get support from the community.

Microsoft.Identity.Web/Microsoft.Identity.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="2.2.0" />
5858
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureADB2C.UI" Version="2.2.0" />
5959
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
60-
<PackageReference Include="Microsoft.Identity.Client" Version="4.5.1" />
60+
<PackageReference Include="Microsoft.Identity.Client" Version="4.6.0" />
6161
</ItemGroup>
6262
</Project>

Microsoft.Identity.Web/TokenAcquisition.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public class TokenAcquisition : ITokenAcquisition
2929
private readonly AzureADOptions _azureAdOptions;
3030
private readonly ConfidentialClientApplicationOptions _applicationOptions;
3131

32-
private readonly IMsalAppTokenCacheProvider _appTokenCacheProvider;
33-
private readonly IMsalUserTokenCacheProvider _userTokenCacheProvider;
32+
private readonly IMsalTokenCacheProvider _tokenCacheProvider;
3433

3534
private IConfidentialClientApplication application;
3635
private readonly IHttpContextAccessor _httpContextAccessor;
@@ -42,20 +41,18 @@ public class TokenAcquisition : ITokenAcquisition
4241
/// This constructor is called by ASP.NET Core dependency injection
4342
/// </summary>
4443
/// <param name="configuration"></param>
45-
/// <param name="appTokenCacheProvider">The App token cache provider</param>
44+
/// <param name="tokenCacheProvider">The App token cache provider</param>
4645
/// <param name="userTokenCacheProvider">The User token cache provider</param>
4746
public TokenAcquisition(
48-
IMsalAppTokenCacheProvider appTokenCacheProvider,
49-
IMsalUserTokenCacheProvider userTokenCacheProvider,
47+
IMsalTokenCacheProvider tokenCacheProvider,
5048
IHttpContextAccessor httpContextAccessor,
5149
IOptions<AzureADOptions> azureAdOptions,
5250
IOptions<ConfidentialClientApplicationOptions> applicationOptions)
5351
{
5452
_httpContextAccessor = httpContextAccessor;
5553
_azureAdOptions = azureAdOptions.Value;
5654
_applicationOptions = applicationOptions.Value;
57-
_appTokenCacheProvider = appTokenCacheProvider;
58-
_userTokenCacheProvider = userTokenCacheProvider;
55+
_tokenCacheProvider = tokenCacheProvider;
5956
}
6057

6158
/// <summary>
@@ -283,7 +280,7 @@ public async Task RemoveAccountAsync(RedirectContext context)
283280
if (account != null)
284281
{
285282
await app.RemoveAsync(account).ConfigureAwait(false);
286-
_userTokenCacheProvider?.ClearAsync().ConfigureAwait(false);
283+
_tokenCacheProvider?.ClearAsync().ConfigureAwait(false);
287284
}
288285
}
289286

@@ -326,8 +323,8 @@ private IConfidentialClientApplication BuildConfidentialClientApplication()
326323
.Build();
327324

328325
// Initialize token cache providers
329-
_appTokenCacheProvider?.InitializeAsync(app.AppTokenCache);
330-
_userTokenCacheProvider?.InitializeAsync(app.UserTokenCache);
326+
_tokenCacheProvider?.InitializeAsync(app.AppTokenCache);
327+
_tokenCacheProvider?.InitializeAsync(app.UserTokenCache);
331328

332329
return app;
333330
}

Microsoft.Identity.Web/TokenCacheProviders/Distributed/DistributedTokenCacheAdapterExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static IServiceCollection AddDistributedAppTokenCache(
2929
this IServiceCollection services)
3030
{
3131
services.AddDistributedMemoryCache();
32-
services.AddSingleton<IMsalAppTokenCacheProvider, MsalAppDistributedTokenCacheProvider>();
32+
services.AddSingleton<IMsalTokenCacheProvider, MsalDistributedTokenCacheAdapter>();
3333
return services;
3434
}
3535

@@ -42,7 +42,7 @@ public static IServiceCollection AddDistributedUserTokenCache(
4242
{
4343
services.AddDistributedMemoryCache();
4444
services.AddHttpContextAccessor();
45-
services.AddSingleton<IMsalUserTokenCacheProvider, MsalPerUserDistributedTokenCacheProvider>();
45+
services.AddSingleton<IMsalTokenCacheProvider, MsalDistributedTokenCacheAdapter>();
4646
return services;
4747
}
4848
}

Microsoft.Identity.Web/TokenCacheProviders/Distributed/MsalAppDistributedTokenCacheProvider.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

Microsoft.Identity.Web/TokenCacheProviders/Distributed/MsalPerUserDistributedTokenCacheProvider.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

Microsoft.Identity.Web/TokenCacheProviders/IMSALUserTokenCacheProvider.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)