Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,10 @@ public async Task Handler_Parameter_withServiceInterface_Works()
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
{
}
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
MicrosoftIdentityWebVersion=$(MicrosoftIdentityWebVersion);
MicrosoftIdentityWebMicrosoftGraphVersion=$(MicrosoftIdentityWebMicrosoftGraphVersion);
MicrosoftIdentityWebUIVersion=$(MicrosoftIdentityWebUIVersion);
MicrosoftIdentityWebDownstreamApiVersion=$(MicrosoftIdentityWebDownstreamApiVersion);
MicrosoftNETCoreAppRuntimeVersion=$(MicrosoftNETCoreAppRuntimeVersion);
SystemNetHttpJsonVersion=$(SystemNetHttpJsonVersion);
MicrosoftGraphVersion=$(MicrosoftGraphVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -28,7 +29,7 @@ else
{
try
{
response = await downstreamAPI.CallWebApiForUserAsync(
response = await downstreamAPI.CallApiForUserAsync(
"DownstreamApi",
options => options.RelativePath = "");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void Main(string[] args)
.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"))
Expand All @@ -85,7 +85,7 @@ public static void Main(string[] args)
#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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
.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"))
Expand All @@ -79,7 +79,7 @@
#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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#endif
#if (GenerateApi)
using Microsoft.Identity.Web;
using Microsoft.Identity.Abstractions;
using System.Net;
#endif
#if (GenerateGraph)
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void Main(string[] args)
.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"))
Expand All @@ -67,7 +67,7 @@ public static void Main(string[] args)
#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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
.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"))
Expand All @@ -61,7 +61,7 @@
#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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if (GenerateApiOrGraph)
#if (GenerateApiOrGraph)
using System.Net;
#endif
using Microsoft.AspNetCore.Mvc;
Expand All @@ -8,6 +8,7 @@
#endif
#if (GenerateApiOrGraph)
using Microsoft.Identity.Web;
using Microsoft.Identity.Abstractions;
#endif

namespace Company.WebApplication1.Pages;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void Main(string[] args)
.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"))
Expand All @@ -80,7 +80,7 @@ public static void Main(string[] args)
#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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
.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"))
Expand All @@ -74,7 +74,7 @@
#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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
#if (GenerateApiOrGraph)
using System.Net;
#endif
Expand All @@ -11,6 +11,7 @@
#endif
#if (GenerateApiOrGraph)
using Microsoft.Identity.Web;
using Microsoft.Identity.Abstractions;
#endif
using Company.WebApplication1.Models;

Expand All @@ -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);
Expand Down
Loading