C# 向带有Auth0的API发送授权承载accessToken时出现错误500
我想使用Auth0 online保护我的web webAPI netcoreapp 2.0,所以我做了所有的事情 我有一个401当我不发送授权时,它是好的 当我不放一个[授权]时,我有一个200 当我使用Bear+accessToken(从Auth0网站上的API复制了令牌)放置授权头时,我有一个500 有人有这个问题吗C# 向带有Auth0的API发送授权承载accessToken时出现错误500,c#,asp.net-core,asp.net-core-2.0,asp.net-core-webapi,auth0,C#,Asp.net Core,Asp.net Core 2.0,Asp.net Core Webapi,Auth0,我想使用Auth0 online保护我的web webAPI netcoreapp 2.0,所以我做了所有的事情 我有一个401当我不发送授权时,它是好的 当我不放一个[授权]时,我有一个200 当我使用Bear+accessToken(从Auth0网站上的API复制了令牌)放置授权头时,我有一个500 有人有这个问题吗 public void ConfigureServices(IServiceCollection services) { services.AddMvc();
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.Authority = "https://******.eu.auth0.com/";
options.Audience = "https://**************.azurewebsites.net/";
});
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseAuthentication();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.UseDeveloperExceptionPage();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
启动时:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters =
new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = TokenConstants.ValidIssuer,
ValidAudience = TokenConstants.ValidAudience,
IssuerSigningKey = JwtSecurityKey.Create(TokenConstants.IssuerSigningKey),
};
});
任何地方:
public static class JwtSecurityKey
{
public static SymmetricSecurityKey Create(string secret)
{
return new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secret));
}
}
我在这里创建我自己的密钥,但是.NET知道如何根据破译它。IssuerSigningKey
这只是一个随机字符串,可以像我想象的“IAMsuperS3cretEcnryptionKey”一样。NET在尝试破译您的令牌时失败了,因为它不知道它是什么,并抛出内部服务器错误,您需要包括AUTH0用于api解密的签名密钥。在启动中:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters =
new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = TokenConstants.ValidIssuer,
ValidAudience = TokenConstants.ValidAudience,
IssuerSigningKey = JwtSecurityKey.Create(TokenConstants.IssuerSigningKey),
};
});
任何地方:
public static class JwtSecurityKey
{
public static SymmetricSecurityKey Create(string secret)
{
return new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secret));
}
}
我在这里创建我自己的密钥,但是.NET知道如何根据
破译它。IssuerSigningKey
这只是一个随机字符串,可以像我想象的“IAMsuperS3cretEcnryptionKey”一样。NET在尝试破译您的令牌时失败了,因为它不知道它是什么,并抛出内部服务器错误,您需要包括AUTH0用于api解密的签名密钥。core 1.1或2.0?,您在哪里/如何生成令牌?您好,这是netcoreapp 2.0。我正在非交互式客户端页面上使用AUTH0生成令牌。core 1.1或2.0?,您在哪里/如何生成令牌?您好,这是netcoreapp 2.0。我正在使用AUTH0生成令牌,在非交互式客户端页面上。