Skip to content

Commit 2db5c37

Browse files
committed
Add authentication setup for PostService
1 parent ad36696 commit 2db5c37

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

backend/src/PostService/PostService.Api/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
app.UseHttpsRedirection();
3333
}
3434

35+
// app.UseAuthentication();
36+
// app.UseAuthorization();
37+
3538
app.MapGet("/health", () => Results.Ok("Healthy"));
3639

3740
app.MapGraphQL();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1+
using Microsoft.AspNetCore.Authentication.JwtBearer;
12
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.IdentityModel.Tokens;
24

35
namespace PostService.Infrastructure;
46

57
public static class DependencyInjection
68
{
79
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services)
810
{
11+
// ToDo: change hard code
12+
// services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
13+
// .AddJwtBearer(options =>
14+
// {
15+
// options.Authority = "http://localhost:8080/realms/fitness-app-realm/";
16+
// options.Audience = "fitness-app-client";
17+
// options.RequireHttpsMetadata = true;
18+
// options.TokenValidationParameters = new TokenValidationParameters
19+
// {
20+
// ValidateIssuer = true,
21+
// ValidateAudience = true,
22+
// ValidateLifetime = true,
23+
// ValidIssuer = "http://localhost:8080/realms/fitness-app-realm/",
24+
// ValidAudience = "fitness-app-client"
25+
// };
26+
// });
27+
//
28+
// services.AddAuthorization();
29+
930
return services;
1031
}
1132
}

backend/src/PostService/PostService.Infrastructure/PostService.Infrastructure.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
1011
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
1112
</ItemGroup>
1213

0 commit comments

Comments
 (0)