Ocelot总是未经授权的Authentication Providerkey
我的问题Ocelot仅在添加AuthenticationProviderKey后才给出未经授权的错误。 Ocelot文件:
{
"Routes": [
{
"DownstreamPathTemplate": "/api/blog",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7001
}
],
"UpstreamPathTemplate": "/api/gateway/blog",
"UpstreamHttpMethod": [ "Get" ],
"AuthenticationOptions": {
"AuthenticationProviderKey": "TestKey",
"AllowedScopes": []
}
},
{
"DownstreamPathTemplate": "/api/notfication",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7011
}
],
"UpstreamPathTemplate": "/api/gateway/notfication",
"UpstreamHttpMethod": [ "Get", "Post" ],
},
{
"DownstreamPathTemplate": "/api/user",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7021
}
],
"UpstreamPathTemplate": "/api/gateway/user",
"UpstreamHttpMethod": [ "Get", "Post" ]
},
{
"DownstreamPathTemplate": "/api/auth",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7031
}
],
"UpstreamPathTemplate": "/api/gateway/auth",
"UpstreamHttpMethod": [ "Post" ],
}
],
“ GlobalConfiguration”:{ “ baseurl”:“ https:// localhost:7000” } }
当我删除位于Ocelot中的AuthenticationProviderKey时, Apigateway program.csİt
string authenticationProviderKey = "TestKey";
builder.Services.AddAuthentication(
//option => {
// option.DefaultAuthenticateScheme = authenticationProviderKey;
// option.DefaultScheme = authenticationProviderKey;
// option.DefaultChallengeScheme = authenticationProviderKey;
//}
)
.AddJwtBearer(authenticationProviderKey, options =>
{
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = signInKey,
ValidateIssuer = true,
ValidIssuer = builder.Configuration["JWT:Issuer"],
ValidateAudience = true,
ValidAudience = builder.Configuration["JWT:Audience"],
ValidateLifetime = true,
ClockSkew = TimeSpan.Zero,
RequireExpirationTime = true
};
});
builder.Services.AddOcelot();
builder.Services.AddControllers();
.
.
.
app.UseAuthentication();
app.UseAuthorization();
await app.UseOcelot();
没有给出未经授权的错误。让我注意,其他服务没有问题。因为他不申请。 Apigateway API存在问题。 怎么了?
My problem ocelot gives only unauthorized erroru after adding AuthenticationProviderKey.
Ocelot file:
{
"Routes": [
{
"DownstreamPathTemplate": "/api/blog",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7001
}
],
"UpstreamPathTemplate": "/api/gateway/blog",
"UpstreamHttpMethod": [ "Get" ],
"AuthenticationOptions": {
"AuthenticationProviderKey": "TestKey",
"AllowedScopes": []
}
},
{
"DownstreamPathTemplate": "/api/notfication",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7011
}
],
"UpstreamPathTemplate": "/api/gateway/notfication",
"UpstreamHttpMethod": [ "Get", "Post" ],
},
{
"DownstreamPathTemplate": "/api/user",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7021
}
],
"UpstreamPathTemplate": "/api/gateway/user",
"UpstreamHttpMethod": [ "Get", "Post" ]
},
{
"DownstreamPathTemplate": "/api/auth",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7031
}
],
"UpstreamPathTemplate": "/api/gateway/auth",
"UpstreamHttpMethod": [ "Post" ],
}
],
"GlobalConfiguration": {
"BaseUrl": "https://localhost:7000"
}
}
APIGateway Program.cs
string authenticationProviderKey = "TestKey";
builder.Services.AddAuthentication(
//option => {
// option.DefaultAuthenticateScheme = authenticationProviderKey;
// option.DefaultScheme = authenticationProviderKey;
// option.DefaultChallengeScheme = authenticationProviderKey;
//}
)
.AddJwtBearer(authenticationProviderKey, options =>
{
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = signInKey,
ValidateIssuer = true,
ValidIssuer = builder.Configuration["JWT:Issuer"],
ValidateAudience = true,
ValidAudience = builder.Configuration["JWT:Audience"],
ValidateLifetime = true,
ClockSkew = TimeSpan.Zero,
RequireExpirationTime = true
};
});
builder.Services.AddOcelot();
builder.Services.AddControllers();
.
.
.
app.UseAuthentication();
app.UseAuthorization();
await app.UseOcelot();
İt is not give unauthorized error when I delete AuthenticationProviderKey located in the ocelot. Let me note that there are no problems with other services. Because he does not apply there. There is a problem with ApiGateway API.
What's wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论