Skip to content

Commit f43789c

Browse files
jmprieurhalter73
andauthored
Update the app to show best practices (#107)
* Update appsettings.json * Update Program.cs * Update Index.cshtml.cs * Update web-app-aspnet/appsettings.json Co-authored-by: Stephen Halter <[email protected]> * Address Stephen's feedback * Update IdWeb --------- Co-authored-by: Stephen Halter <[email protected]>
1 parent 0ed4cfe commit f43789c

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

web-app-aspnet/Pages/Index.cshtml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace sign_in_webapp.Pages;
77

8-
[AuthorizeForScopes(ScopeKeySection = "DownstreamApi:Scopes")]
8+
[AuthorizeForScopes(ScopeKeySection = "DownstreamApis:MicrosoftGraph:Scopes")]
99
public class IndexModel : PageModel
1010
{
1111
private readonly ILogger<IndexModel> _logger;
@@ -21,7 +21,7 @@ public IndexModel(ILogger<IndexModel> logger,
2121

2222
public async Task OnGet()
2323
{
24-
using var response = await _downstreamWebApi.CallApiForUserAsync("DownstreamApi").ConfigureAwait(false);
24+
using var response = await _downstreamWebApi.CallApiForUserAsync("MicrosoftGraph").ConfigureAwait(false);
2525
if (response.StatusCode == System.Net.HttpStatusCode.OK)
2626
{
2727
var apiResult = await response.Content.ReadFromJsonAsync<JsonDocument>().ConfigureAwait(false);

web-app-aspnet/Program.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
// <ms_docref_add_msal>
99
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
10-
IEnumerable<string>? initialScopes = builder.Configuration.GetSection("DownstreamApi:Scopes").Get<IEnumerable<string>>();
10+
IEnumerable<string>? initialScopes = builder.Configuration.GetSection("DownstreamApis:MicrosoftGraph:Scopes").Get<IEnumerable<string>>();
1111

1212
builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration, "AzureAd")
1313
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
14-
.AddDownstreamApi("DownstreamApi", builder.Configuration.GetSection("DownstreamApi"))
1514
.AddInMemoryTokenCaches();
15+
builder.Services.AddDownstreamApis(builder.Configuration.GetSection("DownstreamApis"));
16+
1617
// </ms_docref_add_msal>
1718

1819
// <ms_docref_add_default_controller_for_sign-in-out>

web-app-aspnet/WebApp.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<RootNamespace>sign_in_webapp</RootNamespace>
77
</PropertyGroup>
88
<ItemGroup>
9-
<PackageReference Include="Microsoft.Identity.Web" Version="3.5.0" />
10-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="3.5.0" />
11-
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="3.5.0" />
9+
<PackageReference Include="Microsoft.Identity.Web" Version="3.8.0" />
10+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="3.8.0" />
11+
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="3.8.0" />
1212
</ItemGroup>
1313
</Project>

web-app-aspnet/appsettings.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"Instance": "https://login.microsoftonline.com/",
44
"TenantId": "Enter the tenant ID obtained from the Microsoft Entra admin center",
55
"ClientId": "Enter the client ID obtained from the Microsoft Entra admin center",
6-
"ClientCertificates": [
6+
"ClientCredentials": [
77
{
88
"SourceType": "StoreWithThumbprint",
99
"CertificateStorePath": "CurrentUser/My",
@@ -12,12 +12,14 @@
1212
],
1313
"CallbackPath": "/signin-oidc"
1414
},
15-
"DownstreamApi": {
16-
"BaseUrl": "https://graph.microsoft.com/v1.0/",
17-
"RelativePath": "me",
18-
"Scopes": [
19-
"user.read"
20-
]
15+
"DownstreamApis": {
16+
"MicrosoftGraph" :{
17+
"BaseUrl": "https://graph.microsoft.com/v1.0/",
18+
"RelativePath": "me",
19+
"Scopes": [
20+
"user.read"
21+
]
22+
}
2123
},
2224
"Logging": {
2325
"LogLevel": {

0 commit comments

Comments
 (0)