【发布时间】:2019-12-12 02:12:43
【问题描述】:
我使用 auth0 和 .net core web api,下面是我的配置。
-
在我的 ConfigureServices() 中有
services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.Authority = "https://xxxxxxx.auth0.com/"; options.Audience = "https://localhost:5001"; }); -
在我的 Configure() 方法中,我有
// 2. Enable authentication middleware app.UseAuthentication(); app.UseMvc();
最后在我的 HomeController.cs 中
[HttpGet("private")]
[Authorize]
public IActionResult Private()
{
return Ok(new
{
Message = "Hello from a private endpoint! You need to be authenticated to see this."
});
}
当我尝试使用正确的访问令牌、使用邮递员或我的反应应用程序访问端点时,我得到 401 未授权或www-authenticate: Bearer error="invalid_token"
我按照文档中的示例进行操作,无法弄清楚我在这里做错了什么。请指教。
【问题讨论】:
-
如何获取访问令牌?
标签: asp.net-core asp.net-core-webapi auth0