Skip to content

Commit

Permalink
集成 dapr
Browse files Browse the repository at this point in the history
  • Loading branch information
zlzforever committed Aug 3, 2024
1 parent 92b005c commit 910c4d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/SecurityTokenService/SecurityTokenService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageReference Include="EFCore.NamingConventions" Version="8.0.2" />
<PackageReference Include="Dapr.AspNetCore" Version="1.12.0" />
</ItemGroup>

<ItemGroup>
Expand Down
17 changes: 16 additions & 1 deletion src/SecurityTokenService/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public void ConfigureServices(IServiceCollection services)
Util.DataProtectionKeyAes.Key = Encoding.UTF8.GetBytes(dataProtectionKey);
}

services.AddControllers();
var builder = services.AddControllers();
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("DAPR_HTTP_PORT")))
{
builder.AddDapr();
}

// 影响隐私数据加密、AntiToken 加解密
var dataProtectionBuilder = services.AddDataProtection()
Expand Down Expand Up @@ -140,8 +144,19 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseMiddleware<PublicFacingUrlMiddleware>(Configuration);
app.UseIdentityServer();
app.UseAuthorization();
var inDapr = !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("DAPR_HTTP_PORT"));
if (inDapr)
{
app.UseCloudEvents();
}

app.UseEndpoints(endpoints =>
{
if (inDapr)
{
endpoints.MapSubscribeHandler();
}

endpoints.MapControllers().RequireCors("cors");
});
}
Expand Down

0 comments on commit 910c4d5

Please sign in to comment.