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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Console": {
"FormatterName": "simple",
"FormatterOptions": {
"TimestampFormat": "HH:mm:ss "
}
}
}
}
8 changes: 7 additions & 1 deletion src/backend/ProjectMetadataPlatform.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Console": {
"FormatterName": "simple",
"FormatterOptions": {
"TimestampFormat": "HH:mm:ss "
}
}
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.Identity.Web;
using Microsoft.IdentityModel.Tokens;
using ProjectMetadataPlatform.Application;
using ProjectMetadataPlatform.Application.Auth;
Expand Down Expand Up @@ -100,56 +97,43 @@ JwtBearerEvents jwtBearerEvents
});

_ = serviceCollection
.AddIdentityCore<IdentityUser>()
.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<ProjectMetadataPlatformDbContext>()
.AddDefaultTokenProviders();

var tokenDescriptorInformation = TokenDescriptorInformation.ReadFromEnvVariables();
_ = serviceCollection.Configure<IdentityOptions>(options =>
options.User.RequireUniqueEmail = true
);

_ = serviceCollection
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(
options => { },
options =>
{
options.Authority = EnvironmentUtils.GetEnvVarOrLoadFromFile("AZURE_AUTHORITY");
options.ClientId = EnvironmentUtils.GetEnvVarOrLoadFromFile(
"AZURE_BACKEND_CLIENT_ID"
);
},
"Azure"
);
_ = serviceCollection
.AddAuthentication()
.AddJwtBearer(
"Basic",
options =>
.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = tokenDescriptorInformation.ValidIssuer,
ValidAudience = tokenDescriptorInformation.ValidAudience,
IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(tokenDescriptorInformation.IssuerSigningKey)
),
ClockSkew = Environment.GetEnvironmentVariable("PMP_JWT_CLOCK_SKEW_SECONDS")
is { } clockSkew
? TimeSpan.FromSeconds(
double.Parse(clockSkew, CultureInfo.InvariantCulture)
)
: TimeSpan.FromMinutes(5),
};

options.Events = jwtBearerEvents;
}
);
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = tokenDescriptorInformation.ValidIssuer,
ValidAudience = tokenDescriptorInformation.ValidAudience,
IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(tokenDescriptorInformation.IssuerSigningKey)
),
ClockSkew = Environment.GetEnvironmentVariable("PMP_JWT_CLOCK_SKEW_SECONDS")
is { } clockSkew
? TimeSpan.FromSeconds(
double.Parse(clockSkew, CultureInfo.InvariantCulture)
)
: TimeSpan.FromMinutes(5),
};

options.Events = jwtBearerEvents;
});
}

/// <summary>
Expand Down
Loading