代码拉取完成,页面将自动刷新
using Grpc.Core;
using GrpcService1.Services;
using Microsoft.IdentityModel.Tokens;
using DemoClient = GrpcDemo.Protos.Demo.DemoClient;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpContextAccessor();
builder.Services.AddGrpcReflection();
builder.Services.AddGrpc(o =>
{
o.Interceptors.Add<ParamInterceptor>();
});
builder.Services.AddGrpcClient<DemoClient>(o =>
{
o.Address = new Uri("http://localhost:5210");
}).ConfigureChannel(x =>
{
x.Credentials = ChannelCredentials.SecureSsl;
});
builder.Services.AddAuthentication()
.AddJwtBearer(o =>
{
o.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = false,
ValidateAudience = false,
ValidateLifetime = false,
ValidateIssuerSigningKey = false,
IssuerSigningKey = GlobalConst.RsaPublicSecurityKey
};
});
builder.Services.AddAuthorization();
var app = builder.Build();
app.UseAuthentication(); //经过鉴权中间件,将jwt token转换为claims
app.UseAuthorization();
app.MapGrpcService<DemoService>();
if (app.Environment.IsDevelopment())
{
app.MapGrpcReflectionService().AllowAnonymous(); //启用反射,将grpc服务暴露出来(无需通过proto生成客户端也能调用),允许匿名访问
}
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
app.Run();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。