欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

IdentityServer4實戰(zhàn)中怎么與API單項目整合

IdentityServer4實戰(zhàn)中怎么與API單項目整合,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

創(chuàng)新互聯(lián)長期為1000+客戶提供的網(wǎng)站建設服務,團隊從業(yè)經(jīng)驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為撫順縣企業(yè)提供專業(yè)的網(wǎng)站建設、成都網(wǎng)站設計,撫順縣網(wǎng)站改版等技術服務。擁有十年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。

一.前言

我們在實際使用 IdentityServer4 的時候,可能會在使用 IdentityServer4 項目添加一些API,比如 找回密碼、用戶注冊、修改用戶資料等,這些API與IdentityServer4怎么共存在一個項目呢?

二.整合

1.首先在 Startup.cs 中添加 IdentityServer4

services.AddIdentityServer(options=>options.Authentication.CookieAuthenticationScheme= "Cookies")
                .AddDeveloperSigningCredential()
                .AddInMemoryIdentityResources(Config.GetIdentityResources())
                .AddInMemoryApiResources(Config.GetApis())
                .AddInMemoryClients(Config.GetClients())
                .AddTestUsers(Config.GetUsers());

2.然后在添加 IdentityServer4 下添加認證

services.AddAuthentication("Bearer")
                .AddCookie("Cookies")
                .AddJwtBearer("Bearer", options =>
                {                    //identityserver4 地址 也就是本項目地址
                    options.Authority = "http://localhost:5000";
                    options.RequireHttpsMetadata = false;
                    options.Audience = "api1";
                });

注意事項

  • Cookie Scheme 是非必須的,但是如果不設置會報錯,但是也不會影響正常使用

  • AddAuthentication 必須必須必須 放在 AddIdentityServer 之后

IdentityServer4實戰(zhàn)中怎么與API單項目整合

3.中間件配置

app.UseIdentityServer();

這里只需 UseIdentityServer 即可

三.測試

在 IdentityServer4 項目添加一個 Controller

[Route("identity")]
[Authorize]public class IdentityController : ControllerBase{  
 public IActionResult Get()    {      
 return new JsonResult(from c in User.Claims select new { c.Type, c.Value });    } }

將 IdentityServer4 項目的端口設置為5000,使用密碼模式,下面進行測試:

1.請求Token

IdentityServer4實戰(zhàn)中怎么與API單項目整合

2.請求API

IdentityServer4實戰(zhàn)中怎么與API單項目整合

關于IdentityServer4實戰(zhàn)中怎么與API單項目整合問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關知識。

分享題目:IdentityServer4實戰(zhàn)中怎么與API單項目整合
文章位置:http://www.chinadenli.net/article42/ishhec.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供域名注冊網(wǎng)站策劃品牌網(wǎng)站建設用戶體驗App開發(fā)網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設