我在.net core 1.1中创建了一个Web API。我已经使用Auth0通过社交登录对其进行身份验证。选择的客户端类型为“ API的测试版”。我在.net core 1.1中创建了另一个Web应用程序,该应用程序正在使用另一个Auth0 [常规Web应用程序]来验证社交登录名。
是否可以使用由Web应用程序创建的访问令牌作为Authorization标头传递并获得对Web api方法的访问权限?
谢谢,森希尔
我写了一篇关于Auth0关于与ASP.NET核心JWT令牌API认证,以及如何创建一个使用客户Autorest。
该帖子有一个公开的GitHub存储库,其中提供了整个场景(Web应用程序+ API)。
基本上,您传递JWT令牌,并在Startup.cs上使用以下方法在API上对其进行验证:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
/*Enabling swagger file*/
app.UseSwagger();
/*Enabling Swagger ui, consider doing it on Development env only*/
app.UseSwaggerUi();
/*It's important that this is AFTER app.UseSwagger or the swagger.json file would be innaccesible*/
var options = new JwtBearerOptions
{
Audience = Configuration["auth0:clientId"],
Authority = $"https://{Configuration["auth0:domain"]}/"
};
app.UseJwtBearerAuthentication(options);
/*Normal MVC mappings*/
app.UseMvc();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句