-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
356 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. | ||
|
||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base | ||
WORKDIR /app | ||
EXPOSE 80 | ||
EXPOSE 443 | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build | ||
WORKDIR /src | ||
COPY ["Forge.Yoda.Services.WeatherForecastApi/Forge.Yoda.Services.WeatherForecastApi.csproj", "Forge.Yoda.Services.WeatherForecastApi/"] | ||
RUN dotnet restore "Forge.Yoda.Services.WeatherForecastApi/Forge.Yoda.Services.WeatherForecastApi.csproj" | ||
COPY . . | ||
WORKDIR "/src/Forge.Yoda.Services.WeatherForecastApi" | ||
RUN dotnet build "Forge.Yoda.Services.WeatherForecastApi.csproj" -c Release -o /app/build | ||
|
||
FROM build AS publish | ||
RUN dotnet publish "Forge.Yoda.Services.WeatherForecastApi.csproj" -c Release -o /app/publish /p:UseAppHost=false | ||
|
||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "Forge.Yoda.Services.WeatherForecastApi.dll"] |
27 changes: 27 additions & 0 deletions
27
Forge.Yoda.Services.WeatherForecastApi/Forge.Yoda.Services.WeatherForecastApi.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UserSecretsId>e48e8476-964c-4df5-9dda-abcef6f128df</UserSecretsId> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Forge.Security.Jwt.Service" Version="1.5.1" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.10" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.10" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.5" /> | ||
<PackageReference Include="log4net" Version="2.0.15" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Forge.Yoda.Shared.Models\Forge.Yoda.Shared.Models.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using Forge.Security.Jwt.Service; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.IdentityModel.Tokens; | ||
using Swashbuckle.AspNetCore.Filters; | ||
using System.Text; | ||
|
||
namespace Forge.Yoda.Services.WeatherForecastApi | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
JwtTokenConfiguration jwtTokenConfig = builder.Configuration.GetSection("JwtTokenConfig").Get<JwtTokenConfiguration>(); | ||
builder.Services.AddSingleton(jwtTokenConfig); | ||
|
||
// add JWT bearer token authentication | ||
builder.Services.AddAuthentication(x => | ||
{ | ||
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | ||
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | ||
}).AddJwtBearer(x => | ||
{ | ||
x.RequireHttpsMetadata = true; | ||
x.SaveToken = true; | ||
x.TokenValidationParameters = new TokenValidationParameters | ||
{ | ||
ValidateIssuer = jwtTokenConfig.ValidateIssuer, | ||
ValidIssuer = jwtTokenConfig.Issuer, | ||
ValidateIssuerSigningKey = jwtTokenConfig.ValidateIssuerSigningKey, | ||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtTokenConfig.Secret)), | ||
ValidAudience = jwtTokenConfig.Audience, | ||
ValidateAudience = jwtTokenConfig.ValidateAudience, | ||
ValidateLifetime = jwtTokenConfig.ValidateLifetime, | ||
ClockSkew = TimeSpan.FromMinutes(jwtTokenConfig.ClockSkewInMinutes) | ||
}; | ||
}); | ||
|
||
builder.Services.AddCors(options => | ||
{ | ||
options.AddDefaultPolicy(builder => | ||
{ | ||
builder | ||
.AllowAnyHeader() | ||
.AllowAnyOrigin() | ||
.AllowAnyMethod(); | ||
}); | ||
}); | ||
|
||
builder.Services.AddControllers().AddNewtonsoftJson(); | ||
|
||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(options => | ||
{ | ||
options.AddSecurityDefinition("Access Token", new Microsoft.OpenApi.Models.OpenApiSecurityScheme | ||
{ | ||
BearerFormat = JwtBearerDefaults.AuthenticationScheme, | ||
Description = "Standard Authorization header using the Bearer scheme. Example: \"Bearer {access token}\"", | ||
Name = "Authorization", | ||
Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey, | ||
In = Microsoft.OpenApi.Models.ParameterLocation.Header | ||
}); | ||
|
||
options.OperationFilter<SecurityRequirementsOperationFilter>(); | ||
}); | ||
|
||
builder.Services.AddLogging(options => options.SetMinimumLevel(LogLevel.Trace)); | ||
|
||
var app = builder.Build(); | ||
|
||
ILoggerFactory loggerFactory = (ILoggerFactory)app.Services.GetService(typeof(ILoggerFactory)); | ||
loggerFactory.AddLog4Net(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseRouting(); | ||
|
||
app.UseCors(); | ||
|
||
app.UseAuthentication(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapControllers(); | ||
}); | ||
|
||
app.Run(); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Forge.Yoda.Services.WeatherForecastApi/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"profiles": { | ||
"Forge.Yoda.Services.WeatherForecastApi": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"dotnetRunMessages": true, | ||
"applicationUrl": "https://localhost:7067;http://localhost:5067" | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"Docker": { | ||
"commandName": "Docker", | ||
"launchBrowser": true, | ||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", | ||
"publishAllPorts": true, | ||
"useSSL": true | ||
} | ||
}, | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:15491", | ||
"sslPort": 44322 | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
Forge.Yoda.Services.WeatherForecastApi/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
Oops, something went wrong.