Update version of Microsoft.Identity.Web and Microsoft.Identity.Web.UI to 2.7.0 (#47906)

* update version of Microsoft.Identity.Web and Microsoft.Identity.Web.UI to 2.10.0

* migrated from IDownstreamWebApi to IDownstreamApi

* added Microsoft.Identity.Web.DownstreamApi package

---------

Co-authored-by: Stephen Halter <halter73@gmail.com>
This commit is contained in:
Surayya Huseyn Zada 2023-05-17 10:39:19 +02:00 коммит произвёл GitHub
Родитель 370f9fb5f9
Коммит 0a1469a161
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
29 изменённых файлов: 85 добавлений и 61 удалений

Просмотреть файл

@ -286,9 +286,10 @@
<DuendeIdentityServerStorageVersion>6.0.4</DuendeIdentityServerStorageVersion>
<DuendeIdentityServerEntityFrameworkStorageVersion>6.0.4</DuendeIdentityServerEntityFrameworkStorageVersion>
<MessagePackVersion>2.5.108</MessagePackVersion>
<MicrosoftIdentityWebVersion>1.16.0</MicrosoftIdentityWebVersion>
<MicrosoftIdentityWebMicrosoftGraphVersion>1.16.0</MicrosoftIdentityWebMicrosoftGraphVersion>
<MicrosoftIdentityWebUIVersion>1.16.0</MicrosoftIdentityWebUIVersion>
<MicrosoftIdentityWebVersion>2.10.0</MicrosoftIdentityWebVersion>
<MicrosoftIdentityWebMicrosoftGraphVersion>2.10.0</MicrosoftIdentityWebMicrosoftGraphVersion>
<MicrosoftIdentityWebUIVersion>2.10.0</MicrosoftIdentityWebUIVersion>
<MicrosoftIdentityWebDownstreamApiVersion>2.10.0</MicrosoftIdentityWebDownstreamApiVersion>
<MessagePackAnalyzerVersion>$(MessagePackVersion)</MessagePackAnalyzerVersion>
<MoqVersion>4.10.0</MoqVersion>
<MonoCecilVersion>0.11.2</MonoCecilVersion>

Просмотреть файл

@ -648,10 +648,10 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Builder;
var webApp = WebApplication.Create();
webApp.MapGet("/weatherforecast", (HttpContext context, IDownstreamWebApi downstreamWebApi) => {});
webApp.MapGet("/weatherforecast", (HttpContext context, IDownstreamApi downstreamApi) => {});
// This type doesn't need to be parsable because it should be assumed to be a service type.
public interface IDownstreamWebApi
public interface IDownstreamApi
{
}
""";

Просмотреть файл

@ -31,6 +31,7 @@
<PackageReference Include="Microsoft.Identity.Web" Version="${MicrosoftIdentityWebVersion}" Condition=" '$(IndividualB2CAuth)' == 'True' OR '$(OrganizationalAuth)' == 'True'" />
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="${MicrosoftIdentityWebMicrosoftGraphVersion}" Condition=" '$(GenerateGraph)' == 'True' " />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="${MicrosoftIdentityWebUIVersion}" Condition=" '$(IndividualB2CAuth)' == 'True' OR '$(OrganizationalAuth)' == 'True'" />
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="${MicrosoftIdentityWebDownstreamApiVersion}" Condition=" '$(IndividualB2CAuth)' == 'True' OR '$(OrganizationalAuth)' == 'True'" />
</ItemGroup>
<!--#endif -->

Просмотреть файл

@ -45,6 +45,7 @@
<PackageReference Include="Microsoft.Identity.Web" Version="${MicrosoftIdentityWebVersion}" />
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="${MicrosoftIdentityWebMicrosoftGraphVersion}" Condition=" '$(GenerateGraph)' == 'True' " />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="${MicrosoftIdentityWebUIVersion}" />
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="${MicrosoftIdentityWebDownstreamApiVersion}" />
</ItemGroup>
<!--#endif -->

Просмотреть файл

@ -22,6 +22,7 @@
MicrosoftIdentityWebVersion=$(MicrosoftIdentityWebVersion);
MicrosoftIdentityWebMicrosoftGraphVersion=$(MicrosoftIdentityWebMicrosoftGraphVersion);
MicrosoftIdentityWebUIVersion=$(MicrosoftIdentityWebUIVersion);
MicrosoftIdentityWebDownstreamApiVersion=$(MicrosoftIdentityWebDownstreamApiVersion);
MicrosoftNETCoreAppRuntimeVersion=$(MicrosoftNETCoreAppRuntimeVersion);
SystemNetHttpJsonVersion=$(SystemNetHttpJsonVersion);
MicrosoftGraphVersion=$(MicrosoftGraphVersion);

Просмотреть файл

@ -29,6 +29,7 @@
<PackageReference Include="Microsoft.Identity.Web" Version="${MicrosoftIdentityWebVersion}" Condition=" '$(IndividualB2CAuth)' == 'True' OR '$(OrganizationalAuth)' == 'True'" />
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="${MicrosoftIdentityWebMicrosoftGraphVersion}" Condition=" '$(GenerateGraph)' == 'True' " />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="${MicrosoftIdentityWebUIVersion}" Condition=" '$(IndividualB2CAuth)' == 'True' OR '$(OrganizationalAuth)' == 'True'" />
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="${MicrosoftIdentityWebDownstreamApiVersion}" Condition=" '$(IndividualB2CAuth)' == 'True' OR '$(OrganizationalAuth)' == 'True'" />
</ItemGroup>
<!--#endif -->

Просмотреть файл

@ -29,6 +29,7 @@
<PackageReference Include="Microsoft.Identity.Web" Version="${MicrosoftIdentityWebVersion}" Condition=" '$(IndividualB2CAuth)' == 'True' OR '$(OrganizationalAuth)' == 'True'" />
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="${MicrosoftIdentityWebMicrosoftGraphVersion}" Condition=" '$(GenerateGraph)' == 'True' " />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="${MicrosoftIdentityWebUIVersion}" Condition=" '$(IndividualB2CAuth)' == 'True' OR '$(OrganizationalAuth)' == 'True'" />
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="${MicrosoftIdentityWebDownstreamApiVersion}" Condition=" '$(IndividualB2CAuth)' == 'True' OR '$(OrganizationalAuth)' == 'True'" />
</ItemGroup>
<!--#endif -->

Просмотреть файл

@ -18,6 +18,7 @@
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="${MicrosoftAspNetCoreOpenApiVersion}" Condition="'$(EnableOpenAPI)' == 'True'" />
<PackageReference Include="Microsoft.Identity.Web" Version="${MicrosoftIdentityWebVersion}" Condition="'$(OrganizationalAuth)' == 'True' OR '$(IndividualB2CAuth)' == 'True'"/>
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="${MicrosoftIdentityWebMicrosoftGraphVersion}" Condition=" '$(GenerateGraph)' == 'True' " />
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="${MicrosoftIdentityWebDownstreamApiVersion}" Condition="'$(OrganizationalAuth)' == 'True' OR '$(IndividualB2CAuth)' == 'True'"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="${SwashbuckleAspNetCoreVersion}" Condition="'$(EnableOpenAPI)' == 'True'" />
</ItemGroup>

Просмотреть файл

@ -2,8 +2,9 @@
@using BlazorServerWeb_CSharp
@using Microsoft.Identity.Web
@using Microsoft.Identity.Abstractions
@inject IDownstreamWebApi downstreamAPI
@inject IDownstreamApi downstreamAPI
@inject MicrosoftIdentityConsentAndConditionalAccessHandler ConsentHandler
<h1>Call an API</h1>
@ -28,7 +29,7 @@ else
{
try
{
response = await downstreamAPI.CallWebApiForUserAsync(
response = await downstreamAPI.CallApiForUserAsync(
"DownstreamApi",
options => options.RelativePath = "");

Просмотреть файл

@ -67,7 +67,7 @@ public class Program
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
#if (GenerateApi)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
#endif
#if (GenerateGraph)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
@ -85,7 +85,7 @@ public class Program
#if (GenerateApi)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
#else
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"));

Просмотреть файл

@ -61,7 +61,7 @@ builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
#if (GenerateApi)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
#endif
#if (GenerateGraph)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
@ -79,7 +79,7 @@ builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
#if (GenerateApi)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
#else
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"));

Просмотреть файл

@ -41,14 +41,16 @@ For more info see https:////aka.ms/dotnet-template-ms-identity-platform
////#if (GenerateApiOrGraph)
// "DownstreamApi": {
// /*
// 'Scopes' contains space separated scopes of the Web API you want to call. This can be:
// 'Scopes' contains scopes of the Web API you want to call. This can be:
// - a scope for a V2 application (for instance api://b3682cc7-8b30-4bd2-aaba-080c6bf0fd31/access_as_user)
// - a scope corresponding to a V1 application (for instance <App ID URI>/.default, where <App ID URI> is the
// App ID URI of a legacy v1 Web application
// Applications are registered in the https://portal.azure.com portal.
// */
// "BaseUrl": "[WebApiUrl]",
// "Scopes": "user.read"
// "Scopes": [
// "user.read"
// ]
// },
////#endif
////#if (IndividualLocalAuth)

Просмотреть файл

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization;
#endif
#if (GenerateApi)
using Microsoft.Identity.Web;
using Microsoft.Identity.Abstractions;
using System.Net;
#endif
#if (GenerateGraph)
@ -36,19 +37,19 @@ public class WeatherForecastController : ControllerBase
private readonly ILogger<WeatherForecastController> _logger;
#if (GenerateApi)
private readonly IDownstreamWebApi _downstreamWebApi;
private readonly IDownstreamApi _downstreamApi;
public WeatherForecastController(ILogger<WeatherForecastController> logger,
IDownstreamWebApi downstreamWebApi)
IDownstreamApi downstreamApi)
{
_logger = logger;
_downstreamWebApi = downstreamWebApi;
_downstreamApi = downstreamApi;
}
[HttpGet]
public async Task<IEnumerable<WeatherForecast>> Get()
{
using var response = await _downstreamWebApi.CallWebApiForUserAsync("DownstreamApi").ConfigureAwait(false);
using var response = await _downstreamApi.CallApiForUserAsync("DownstreamApi").ConfigureAwait(false);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var apiResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

Просмотреть файл

@ -53,7 +53,7 @@ public class Program
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi()
#if (GenerateApi)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
#endif
#if (GenerateGraph)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
@ -67,7 +67,7 @@ public class Program
#if (GenerateApi)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAdB2C"))
.EnableTokenAcquisitionToCallDownstreamApi()
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
#else
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAdB2C"));

Просмотреть файл

@ -47,7 +47,7 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi()
#if (GenerateApi)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
#endif
#if (GenerateGraph)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
@ -61,7 +61,7 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
#if (GenerateApi)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAdB2C"))
.EnableTokenAcquisitionToCallDownstreamApi()
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
#else
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAdB2C"));

Просмотреть файл

@ -52,14 +52,16 @@ For more info see https:////aka.ms/dotnet-template-ms-identity-platform
////#if (GenerateApiOrGraph)
// "DownstreamApi": {
// /*
// 'Scopes' contains space separated scopes of the Web API you want to call. This can be:
// 'Scopes' contains scopes of the Web API you want to call. This can be:
// - a scope for a V2 application (for instance api://b3682cc7-8b30-4bd2-aaba-080c6bf0fd31/access_as_user)
// - a scope corresponding to a V1 application (for instance <App ID URI>/.default, where <App ID URI> is the
// App ID URI of a legacy v1 Web application
// Applications are registered in the https://portal.azure.com portal.
// */
// "BaseUrl": "[WebApiUrl]",
// "Scopes": "user.read"
// "Scopes": [
// "user.read"
// ]
// },
////#endif
"Logging": {

Просмотреть файл

@ -1,4 +1,4 @@
#if (GenerateApiOrGraph)
#if (GenerateApiOrGraph)
using System.Net;
#endif
using Microsoft.AspNetCore.Mvc;
@ -8,6 +8,7 @@ using Microsoft.Graph;
#endif
#if (GenerateApiOrGraph)
using Microsoft.Identity.Web;
using Microsoft.Identity.Abstractions;
#endif
namespace Company.WebApplication1.Pages;
@ -20,18 +21,18 @@ public class IndexModel : PageModel
private readonly ILogger<IndexModel> _logger;
#if (GenerateApi)
private readonly IDownstreamWebApi _downstreamWebApi;
private readonly IDownstreamApi _downstreamApi;
public IndexModel(ILogger<IndexModel> logger,
IDownstreamWebApi downstreamWebApi)
IDownstreamApi downstreamApi)
{
_logger = logger;
_downstreamWebApi = downstreamWebApi;
_downstreamApi = downstreamApi;
}
public async Task OnGet()
{
using var response = await _downstreamWebApi.CallWebApiForUserAsync("DownstreamApi").ConfigureAwait(false);
using var response = await _downstreamApi.CallApiForUserAsync("DownstreamApi").ConfigureAwait(false);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var apiResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

Просмотреть файл

@ -62,7 +62,7 @@ public class Program
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
#if (GenerateApi)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
#endif
#if (GenerateGraph)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
@ -80,7 +80,7 @@ public class Program
#if (GenerateApi)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
#else
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"));

Просмотреть файл

@ -56,7 +56,7 @@ builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
#if (GenerateApi)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
#endif
#if (GenerateGraph)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
@ -74,7 +74,7 @@ builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
#if (GenerateApi)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
#else
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"));

Просмотреть файл

@ -41,14 +41,16 @@ For more info see https:////aka.ms/dotnet-template-ms-identity-platform
////#if (GenerateApiOrGraph)
// "DownstreamApi": {
// /*
// 'Scopes' contains space separated scopes of the Web API you want to call. This can be:
// 'Scopes' contains scopes of the Web API you want to call. This can be:
// - a scope for a V2 application (for instance api://b3682cc7-8b30-4bd2-aaba-080c6bf0fd31/access_as_user)
// - a scope corresponding to a V1 application (for instance <App ID URI>/.default, where <App ID URI> is the
// App ID URI of a legacy v1 Web application
// Applications are registered in the https://portal.azure.com portal.
// */
// "BaseUrl": "[WebApiUrl]",
// "Scopes": "user.read"
// "Scopes": [
// "user.read"
// ]
// },
////#endif
////#if (IndividualLocalAuth)

Просмотреть файл

@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
#if (GenerateApiOrGraph)
using System.Net;
#endif
@ -11,6 +11,7 @@ using Microsoft.Graph;
#endif
#if (GenerateApiOrGraph)
using Microsoft.Identity.Web;
using Microsoft.Identity.Abstractions;
#endif
using Company.WebApplication1.Models;
@ -24,19 +25,19 @@ public class HomeController : Controller
private readonly ILogger<HomeController> _logger;
#if (GenerateApi)
private readonly IDownstreamWebApi _downstreamWebApi;
private readonly IDownstreamApi _downstreamApi;
public HomeController(ILogger<HomeController> logger,
IDownstreamWebApi downstreamWebApi)
IDownstreamApi downstreamApi)
{
_logger = logger;
_downstreamWebApi = downstreamWebApi;
_downstreamApi = downstreamApi;
}
[AuthorizeForScopes(ScopeKeySection = "DownstreamApi:Scopes")]
public async Task<IActionResult> Index()
{
using var response = await _downstreamWebApi.CallWebApiForUserAsync("DownstreamApi").ConfigureAwait(false);
using var response = await _downstreamApi.CallApiForUserAsync("DownstreamApi").ConfigureAwait(false);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var apiResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

Просмотреть файл

@ -62,7 +62,7 @@ public class Program
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
#if (GenerateApi)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
#endif
#if (GenerateGraph)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
@ -80,7 +80,7 @@ public class Program
#if (GenerateApi)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
#else
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"));

Просмотреть файл

@ -56,7 +56,7 @@ builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
#if (GenerateApi)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
#endif
#if (GenerateGraph)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
@ -74,7 +74,7 @@ builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
#if (GenerateApi)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
#else
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAdB2C"));

Просмотреть файл

@ -41,14 +41,16 @@ For more info see https:////aka.ms/dotnet-template-ms-identity-platform
////#if (GenerateApiOrGraph)
// "DownstreamApi": {
// /*
// 'Scopes' contains space separated scopes of the Web API you want to call. This can be:
// 'Scopes' contains scopes of the Web API you want to call. This can be:
// - a scope for a V2 application (for instance api://b3682cc7-8b30-4bd2-aaba-080c6bf0fd31/access_as_user)
// - a scope corresponding to a V1 application (for instance <App ID URI>/.default, where <App ID URI> is the
// App ID URI of a legacy v1 Web application
// Applications are registered in the https://portal.azure.com portal.
// */
// "BaseUrl": "[WebApiUrl]",
// "Scopes": "user.read"
// "Scopes": [
// "user.read"
// ]
// },
////#endif
////#if (IndividualLocalAuth)

Просмотреть файл

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
#if (GenerateApi)
using Microsoft.Identity.Web;
using Microsoft.Identity.Abstractions;
#endif
#if (OrganizationalAuth || IndividualB2CAuth)
using Microsoft.Identity.Web.Resource;
@ -35,13 +36,13 @@ public class WeatherForecastController : ControllerBase
private readonly ILogger<WeatherForecastController> _logger;
#if (GenerateApi)
private readonly IDownstreamWebApi _downstreamWebApi;
private readonly IDownstreamApi _downstreamApi;
public WeatherForecastController(ILogger<WeatherForecastController> logger,
IDownstreamWebApi downstreamWebApi)
IDownstreamApi downstreamApi)
{
_logger = logger;
_downstreamWebApi = downstreamWebApi;
_downstreamApi = downstreamApi;
}
#if (EnableOpenAPI)
@ -51,7 +52,7 @@ public class WeatherForecastController : ControllerBase
#endif
public async Task<IEnumerable<WeatherForecast>> Get()
{
using var response = await _downstreamWebApi.CallWebApiForUserAsync("DownstreamApi").ConfigureAwait(false);
using var response = await _downstreamApi.CallApiForUserAsync("DownstreamApi").ConfigureAwait(false);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var apiResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

Просмотреть файл

@ -10,6 +10,7 @@ using Graph = Microsoft.Graph;
#endif
#if (OrganizationalAuth || IndividualB2CAuth)
using Microsoft.Identity.Web;
using Microsoft.Identity.Abstractions;
using Microsoft.Identity.Web.Resource;
#endif
#if (OrganizationalAuth || IndividualB2CAuth || GenerateGraph || WindowsAuth || EnableOpenAPI)
@ -30,7 +31,7 @@ public class Program
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi()
#if (GenerateApi)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
#endif
#if (GenerateGraph)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
@ -44,7 +45,7 @@ public class Program
#if (GenerateApi)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAdB2C"))
.EnableTokenAcquisitionToCallDownstreamApi()
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
#else
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAdB2C"));
@ -101,11 +102,11 @@ public class Program
};
#if (GenerateApi)
app.MapGet("/weatherforecast", async (HttpContext httpContext, IDownstreamWebApi downstreamWebApi) =>
app.MapGet("/weatherforecast", async (HttpContext httpContext, IDownstreamApi downstreamApi) =>
{
httpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);
using var response = await downstreamWebApi.CallWebApiForUserAsync("DownstreamApi").ConfigureAwait(false);
using var response = await downstreamApi.CallApiForUserAsync("DownstreamApi").ConfigureAwait(false);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var apiResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

Просмотреть файл

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
using Graph = Microsoft.Graph;
#endif
using Microsoft.Identity.Web;
using Microsoft.Identity.Abstractions;
using Microsoft.Identity.Web.Resource;
var builder = WebApplication.CreateBuilder(args);
@ -18,7 +19,7 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi()
#if (GenerateApi)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
#endif
#if (GenerateGraph)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
@ -32,7 +33,7 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
#if (GenerateApi)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAdB2C"))
.EnableTokenAcquisitionToCallDownstreamApi()
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
#else
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAdB2C"));
@ -68,11 +69,11 @@ var summaries = new[]
};
#if (GenerateApi)
app.MapGet("/weatherforecast", async (HttpContext httpContext, IDownstreamWebApi downstreamWebApi) =>
app.MapGet("/weatherforecast", async (HttpContext httpContext, IDownstreamApi downstreamApi) =>
{
httpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);
using var response = await downstreamWebApi.CallWebApiForUserAsync("DownstreamApi").ConfigureAwait(false);
using var response = await downstreamApi.CallApiForUserAsync("DownstreamApi").ConfigureAwait(false);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var apiResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

Просмотреть файл

@ -23,7 +23,7 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi()
#if (GenerateApi)
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
#endif
#if (GenerateGraph)
.AddMicrosoftGraph(builder.Configuration.GetSection("DownstreamApi"))
@ -37,7 +37,7 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
#if (GenerateApi)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAdB2C"))
.EnableTokenAcquisitionToCallDownstreamApi()
.AddDownstreamWebApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
#else
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAdB2C"));

Просмотреть файл

@ -45,14 +45,16 @@ For more info see https:////aka.ms/dotnet-template-ms-identity-platform
////#if (GenerateApiOrGraph)
// "DownstreamApi": {
// /*
// 'Scopes' contains space separated scopes of the Web API you want to call. This can be:
// 'Scopes' contains scopes of the Web API you want to call. This can be:
// - a scope for a V2 application (for instance api://b3682cc7-8b30-4bd2-aaba-080c6bf0fd31/access_as_user)
// - a scope corresponding to a V1 application (for instance <App ID URI>/.default, where <App ID URI> is the
// App ID URI of a legacy v1 Web application
// Applications are registered in the https://portal.azure.com portal.
// */
// "BaseUrl": "[WebApiUrl]",
// "Scopes": "user.read"
// "Scopes": [
// "user.read"
// ]
// },
////#endif
"Logging": {