2017-09-26 46 views
0

我想在线上使用Auth0来保护我的web webAPI netcoreapp 2.0,所以我做了所有the steps向我的API发送授权承载accessToken时出现错误500 Auth0

我有一个401,当我不发送授权,没关系。

我有一个200的时候,我不把[授权]

我有一个500的时候,我把Authorization头与承载+的accessToken(复制从API上Auth0网站上的令牌)

有没有人有这个问题?

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(); 
} 
+0

核心1.1或2.0?,在哪里/你如何生成令牌? –

+0

嗨,这是一个netcoreapp 2.0 我在非交互式客户端页面上生成带有Auth0的令牌。 –

回答

0

在启动:

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通过尝试破译你的令牌,因为它不知道它是什么,并引发内部服务器错误,你需要包括signi ng密钥AUTH0使用你的api来解密它。

相关问题