.Net Core Web 的 Auth0 身份验证 API
Auth0 Authentication for .Net Core Web API
我有一个在 .net core 1.1 中创建的网站 API。我已经使用 Auth0 通过社交登录对其进行身份验证。选择的客户端类型是“API's BETA”。
我有另一个在 .net core 1.1 中创建的 Web 应用程序,它使用另一个 Auth0 [常规 Web 应用程序] 来验证社交登录。
是否可以使用 Web 应用程序创建的访问令牌作为授权 header 传递并访问 Web api 方法?
谢谢,
森德希尔
我在 Auth0 上写了一个 post 关于 API authentication with JWT tokens on ASP.NET Core and how to create clients using Autorest。
post 有一个 public GitHub repo,整个场景(Web 应用程序 + API)可用。
基本上,您传递 JWT 令牌并在 API 上使用您的 Startup.cs:
验证它
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();
}
我有一个在 .net core 1.1 中创建的网站 API。我已经使用 Auth0 通过社交登录对其进行身份验证。选择的客户端类型是“API's BETA”。 我有另一个在 .net core 1.1 中创建的 Web 应用程序,它使用另一个 Auth0 [常规 Web 应用程序] 来验证社交登录。
是否可以使用 Web 应用程序创建的访问令牌作为授权 header 传递并访问 Web api 方法?
谢谢, 森德希尔
我在 Auth0 上写了一个 post 关于 API authentication with JWT tokens on ASP.NET Core and how to create clients using Autorest。
post 有一个 public GitHub repo,整个场景(Web 应用程序 + API)可用。
基本上,您传递 JWT 令牌并在 API 上使用您的 Startup.cs:
验证它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();
}