簡體   English   中英

.Net Core Web API的Auth0身份驗證

[英]Auth0 Authentication for .Net Core Web API

我在.net核心1.1中創建了一個Web API。 我使用Auth0通過社交登錄對其進行身份驗證。 選擇的客戶端類型是“API的BETA”。 我在.net核心1.1中創建了另一個Web應用程序,它使用另一個Auth0 [常規Web應用程序]來驗證社交登錄。

是否可以使用Web應用程序創建的訪問令牌作為授權標頭傳遞並訪問Web api方法?

謝謝,Sendhil

我寫了一篇關於Auth0關於與ASP.NET核心JWT令牌API認證 ,以及如何創建一個使用客戶Autorest

該帖子有一個公共GitHub repo ,可以使用整個場景(Web app + API)。

基本上,您在Startup.cs上傳遞JWT令牌並在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();

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM