Skip to content

Commit

Permalink
Merge pull request #32 from damienbod/net9
Browse files Browse the repository at this point in the history
Update .NET 9
  • Loading branch information
damienbod authored Jan 2, 2025
2 parents 818558d + 6d92458 commit 50c3344
Show file tree
Hide file tree
Showing 25 changed files with 152 additions and 168 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0'
dotnet-version: '9.0'
include-prerelease: True
- name: Build AngularMicrosoftEntraIDMultipleApis
run: dotnet build ./AngularMicrosoftEntraIDMultipleApis/ApiWithMutlipleApis.sln
Expand Down
14 changes: 3 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
**/node_modules/
**/dist/
**/*.csproj.user
/AngularAzureADMultipleApis/LogsServiceApi.txt
/BlazorWithApis/LogsServiceApi.txt
/ConfidentialClientCredentialsCertificate/LogsServiceApi.txt
/ConfidentialClientCredentialsCertificate/LogsMyServerRenderedPortal.txt
/DecryptionCertificates/LogsApiDecryptionCertificates.txt
/DecryptionCertificates/LogsPortalDecryptionCertificates.txt
/AngularAzureADMultipleApis/AngularAzureAD/debug.log
/ClientCredentialsFlows/LogsServiceApi.txt
/AngularAzureADMultipleApis/_logs-ApiWithMutlipleApis.txt
/AngularAzureADMultipleApis/_logs-ServiceApi.txt
/ConfidentialClientCredentialsCertificate/_logs-MyServerRenderedPortal.txt
/ConfidentialClientCredentialsCertificate/_logs-ServiceApi.txt
**/_logs*
**/Logs*
**/*.user
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCs7HI0KWqXEjH1fxXdkgVHg+1UgbtBhwkeZ3WhBsTGcwlqGUmzqlhKiR2hTd9G
d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G2VroAiwHZR6ABJDbwmIaStW1JBjtu2u/LML1gjk+JM0CQQD97fRY4v/R
GCwFxZG9NkSUCRkCM4SpxeryChGwMymVoF/ugRhvw4VmR8qCFP8Set+KieXVZpeTGca/dmOtoBov
AkEA5Rp7ZiPp1zAyqWcqzeWAkfVPK9Cmfugs4tKBQkxHtdcb0OdObPd964HT1vH0lJ4eR/XhafWY
5q8rnwQAmyf04wJBAMNCpmFvdJ15w+hQS0g/Ia7f7A4oRXwzR/4ExiNCxFhdcUc6l+rhY4QJ8mvi
711rhNfIQCa/9BBWguEZjX6mnVsCQCaZuaTR9Do/cqm8KigavPjangZB12uWbsmgsgqbk5F9tsAR
2NLfOCYP78NNbOoFYhC5ysrxiFuFtBHMuNVrfAUCQQDqhqY1m1hyWXpOneFJbt4wHTun4QhLhJ6N
yijNL2phxhaM6SgT3lsF+lwjD44UkiT2JOnXwaNYEadK7G2aI0bK
-----END RSA PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
-----BEGIN CERTIFICATE-----
MIICQDCCAamgAwIBAgIJAIKGapdMCt4NMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNVBAMTCWxvY2Fs
aG9zdDAeFw0yMDAyMjAyMjU3MjFaFw0zMDAyMjEyMjU3MjFaMBQxEjAQBgNVBAMTCWxvY2FsaG9z
dDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEArOxyNClqlxIx9X8V3ZIFR4PtVIG7QYcJHmd1
oQbExnMJahlJs6pYSokdoU3fRnTIUJtbRXlPagDKZoJcUfl4KGaBL/bqF8P03noHSr59Vd3sU8Xl
CyAxiTlyusENTPuBSzK+8wVpTIVpqnG2Exx1cMGHfsnA0R1NzQCMQ3zFEkECAwEAAaOBmTCBljAS
BgNVHRMBAf8ECDAGAQH/AgEDMA4GA1UdDwEB/wQEAwIB/jAUBgNVHREEDTALgglsb2NhbGhvc3Qw
OwYDVR0lBDQwMgYIKwYBBQUHAwEGCCsGAQUFB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TIFICATE-----
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<UserSecretsId>3e9ac996-8e75-4dd9-9a5b-27a6e01a3f3d</UserSecretsId>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Identity.Web" Version="2.16.0" />
<PackageReference Include="Microsoft.Identity.Web.GraphServiceClient" Version="2.16.0" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.4.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="3.5.0" />
<PackageReference Include="Microsoft.Identity.Web.GraphServiceClient" Version="3.5.0" />
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="14.3.0" />

<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.0" NoWarn="NU1605" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" NoWarn="NU1605" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.0" NoWarn="NU1605" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />

<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.0" />
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.3.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.2" />
<PackageReference Include="Azure.Identity" Version="1.13.1" />

<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.AzureApp" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />

</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace ApiWithMutlipleApis.Controllers;

[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[AuthorizeForScopes(Scopes = new string[] { "api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user" })]
[AuthorizeForScopes(Scopes = ["api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user"])]
[ApiController]
[Route("[controller]")]
public class DelegatedUserApiCallsController : ControllerBase
{
private UserApiClientService _userApiClientService;
private readonly UserApiClientService _userApiClientService;

public DelegatedUserApiCallsController(UserApiClientService userApiClientService)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@

namespace ApiWithMutlipleApis.Controllers;

[Authorize(Policy = "ValidateAccessTokenPolicy",
AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[AuthorizeForScopes(Scopes = new string[] { "api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user" })]
[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[AuthorizeForScopes(Scopes = ["api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user"])]
[ApiController]
[Route("[controller]")]
public class DirectApiController : ControllerBase
{
[HttpGet]
public IEnumerable<string> Get()
{
return new List<string> { "some data", "more data", "loads of data" };
return ["some data", "more data", "loads of data"];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace ApiWithMutlipleApis.Controllers;

[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[AuthorizeForScopes(Scopes = new string[] { "User.ReadBasic.All", "user.read" })]
[AuthorizeForScopes(Scopes = ["User.ReadBasic.All", "user.read"])]
[ApiController]
[Route("[controller]")]
public class GraphApiCallsController : ControllerBase
{
private GraphApiClientService _graphApiClientService;
private readonly GraphApiClientService _graphApiClientService;

public GraphApiCallsController(GraphApiClientService graphApiClientService)
{
Expand All @@ -24,7 +24,7 @@ public async Task<IEnumerable<string>> Get()
{
var userData = await _graphApiClientService.GetGraphApiUser();

return new List<string> { $"DisplayName: {userData.DisplayName}",
$"GivenName: {userData.GivenName}", $"AboutMe: {userData.AboutMe}" };
return [ $"DisplayName: {userData!.DisplayName}",
$"GivenName: {userData!.GivenName}", $"AboutMe: {userData!.AboutMe}" ];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace ApiWithMutlipleApis.Controllers;

[Authorize(Policy = "ValidateAccessTokenPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[AuthorizeForScopes(Scopes = new string[] { "api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user" })]
[AuthorizeForScopes(Scopes = ["api://2b50a014-f353-4c10-aace-024f19a55569/access_as_user"])]
[ApiController]
[Route("[controller]")]
public class ServiceApiCallsController : ControllerBase
{
private ServiceApiClientService _serviceApiClientService;
private readonly ServiceApiClientService _serviceApiClientService;

public ServiceApiCallsController(ServiceApiClientService serviceApiClientService)
{
Expand Down
26 changes: 12 additions & 14 deletions AngularMicrosoftEntraIDMultipleApis/ApiWithMutlipleApis/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,30 @@

Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.AzureApp()
.CreateBootstrapLogger();

Log.Information("Starting ApiWithMutlipleApis application");

try
{
Log.Information("Starting ApiWithMutlipleApis");

var builder = WebApplication.CreateBuilder(args);
var builder = WebApplication.CreateBuilder(args);

builder.Host.UseSerilog((context, loggerConfiguration) => loggerConfiguration
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}")
.ReadFrom.Configuration(context.Configuration));

builder.Host.UseSerilog((context, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(context.Configuration));
var app = builder
.ConfigureServices()
.ConfigurePipeline();

var app = builder
.ConfigureServices()
.ConfigurePipeline();

app.Run();
app.Run();
}
catch (Exception ex) when(ex.GetType().Name is not "StopTheHostException"
&& ex.GetType().Name is not "HostAbortedException")
catch (Exception ex) when (ex.GetType().Name is not "StopTheHostException" && ex.GetType().Name is not "HostAbortedException")
{
Log.Fatal(ex, "Unhandled exception");
}
finally
{
Log.Information("Shut down complete");
Log.CloseAndFlush();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class ServiceApiClientService
private readonly IHttpClientFactory _clientFactory;
private readonly ITokenAcquisition _tokenAcquisition;

public ServiceApiClientService(
ITokenAcquisition tokenAcquisition,
public ServiceApiClientService(ITokenAcquisition tokenAcquisition,
IHttpClientFactory clientFactory)
{
_clientFactory = clientFactory;
Expand All @@ -19,12 +18,10 @@ public ServiceApiClientService(

public async Task<IEnumerable<string>> GetApiDataAsync()
{

var client = _clientFactory.CreateClient();

var scope = "api://b178f3a5-7588-492a-924f-72d7887b7e48/.default"; // CC flow access_as_application";
var accessToken = await _tokenAcquisition.GetAccessTokenForAppAsync(scope)
.ConfigureAwait(false);
var accessToken = await _tokenAcquisition.GetAccessTokenForAppAsync(scope);

client.BaseAddress = new Uri("https://localhost:44324");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
Expand All @@ -36,7 +33,7 @@ public async Task<IEnumerable<string>> GetApiDataAsync()
var data = await JsonSerializer.DeserializeAsync<List<string>>(
await response.Content.ReadAsStreamAsync());

if(data != null)
if (data != null)
return data;

return Array.Empty<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ public class UserApiClientService
private readonly IHttpClientFactory _clientFactory;
private readonly ITokenAcquisition _tokenAcquisition;

public UserApiClientService(
ITokenAcquisition tokenAcquisition,
IHttpClientFactory clientFactory)
public UserApiClientService(ITokenAcquisition tokenAcquisition, IHttpClientFactory clientFactory)
{
_clientFactory = clientFactory;
_tokenAcquisition = tokenAcquisition;
}

public async Task<IEnumerable<string>> GetApiDataAsync()
{

var client = _clientFactory.CreateClient();

var scopes = new List<string> { "api://b2a09168-54e2-4bc4-af92-a710a64ef1fa/access_as_user" };
Expand All @@ -37,10 +34,9 @@ public async Task<IEnumerable<string>> GetApiDataAsync()

var data = await JsonSerializer.DeserializeAsync<List<string>>(stream);

if (data != null)
return data;
if (data != null) return data;

return Array.Empty<string>();
return [];
}

throw new ApplicationException("oh no...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace ApiWithMutlipleApis;

internal static class HostingExtensions
internal static class StartupExtensions
{
public static WebApplication ConfigureServices(this WebApplicationBuilder builder)
{
Expand Down Expand Up @@ -81,15 +81,15 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde
c.AddSecurityDefinition(securityScheme.Reference.Id, securityScheme);
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{securityScheme, new string[] { }}
{securityScheme, Array.Empty<string>()}
});

c.SwaggerDoc("v1", new OpenApiInfo { Title = "ApiWithMutlipleApis", Version = "v1" });
});

return builder.Build();
}

public static WebApplication ConfigurePipeline(this WebApplication app)
{
IdentityModelEventSource.ShowPII = true;
Expand All @@ -105,12 +105,9 @@ public static WebApplication ConfigurePipeline(this WebApplication app)
app.UseCors("AllowAllOrigins");

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();

return app;
Expand Down
Loading

0 comments on commit 50c3344

Please sign in to comment.