日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
如何在Ocelot網(wǎng)關中實現(xiàn)IdentityServer4密碼模式

本篇內容介紹了“如何在Ocelot網(wǎng)關中實現(xiàn)IdentityServer4密碼模式”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

站在用戶的角度思考問題,與客戶深入溝通,找到東興網(wǎng)站設計與東興網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設計與互聯(lián)網(wǎng)技術結合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站建設、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名與空間、網(wǎng)頁空間、企業(yè)郵箱。業(yè)務覆蓋東興地區(qū)。

概述

IdentityServer4 是為ASP.NET Core 2.系列量身打造的一款基于 OpenID Connect 和 OAuth 2.0  認證框架。將identityserver部署在你的應用中,具備如下的特點可以為你的應用(如網(wǎng)站、本地應用、移動端、服務)做集中式的登錄邏輯和工作流控制。IdentityServer是完全實現(xiàn)了OpenID  Connect協(xié)議標準。在各種類型的應用上實現(xiàn)單點登錄登出。為各種各樣的客戶端頒發(fā)access  token令牌,如服務與服務之間的通訊、網(wǎng)站應用、SPAS和本地應用或者移動應用等。

OAuth 2.0 默認四種授權模式(GrantType):

  • 授權碼模式(authorization_code)

  • 簡化模式(implicit)

  • 密碼模式(password)

  • 客戶端模式(client_credentials)

我們一般項目在api訪問的時候,大部分是基于賬號密碼的方式進行訪問接口。比如app端的用戶。

下面我們來看下怎么實現(xiàn)密碼模式(password)。

主要實現(xiàn)方式

1、在認證項目中,創(chuàng)建ProfileService

public class ProfileService : IProfileService     {         public async Task GetProfileDataAsync(ProfileDataRequestContext context)         {             var claims = context.Subject.Claims.ToList();             context.IssuedClaims = claims.ToList();         }         public async Task IsActiveAsync(IsActiveContext context)         {             context.IsActive = true;         }     }

2、創(chuàng)建ResourceOwnerPasswordValidator,進行賬號密碼認證

public class ResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator     {         public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)         {             //根據(jù)context.UserName和context.Password與數(shù)據(jù)庫的數(shù)據(jù)做校驗,判斷是否合法             if (context.UserName == "conan" && context.Password == "123")             {                 context.Result = new GrantValidationResult(                 subject: context.UserName,                 authenticationMethod: "custom",                 claims: new Claim[] { new Claim("Name", context.UserName), new Claim("UserId", "111"), new Claim("RealName", "conan"), new Claim("Email", "373197550@qq.com") });             }             else             {                 //驗證失敗                 context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "invalid custom credential");             }         }     }

3、調整AllowedGrantTypes 和AllowedScopes

client.AllowedGrantTypes = GrantTypes.ResourceOwnerPassword;                     List aas = new List();                     aas.AddRange(config.AllowedScopes);                     aas.Add(IdentityServerConstants.StandardScopes.OpenId);                     aas.Add(IdentityServerConstants.StandardScopes.Profile);                     client.AllowedScopes = aas.ToArray();

4、ConfigureServices增加AddInMemoryIdentityResources、AddResourceOwnerValidator、AddProfileService

//注冊服務             var idResources = new List             {               new IdentityResources.OpenId(), //必須要添加,否則報無效的 scope 錯誤               new IdentityResources.Profile()             };               var section = Configuration.GetSection("SSOConfig");             services.AddIdentityServer()          .AddDeveloperSigningCredential()            .AddInMemoryIdentityResources(idResources)          .AddInMemoryApiResources(SSOConfig.GetApiResources(section))          .AddInMemoryClients(SSOConfig.GetClients(section))               .AddResourceOwnerValidator()             .AddProfileService();             services.AddControllers().SetCompatibilityVersion(CompatibilityVersion.Latest);

5、在認證項目進行驗證,測試成功

如何在Ocelot網(wǎng)關中實現(xiàn)IdentityServer4密碼模式

6、修改地址,在網(wǎng)關項目進行認證,測試成功

如何在Ocelot網(wǎng)關中實現(xiàn)IdentityServer4密碼模式

代碼地址:

https://gitee.com/conanOpenSource_admin/Example

“如何在Ocelot網(wǎng)關中實現(xiàn)IdentityServer4密碼模式”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質量的實用文章!


分享標題:如何在Ocelot網(wǎng)關中實現(xiàn)IdentityServer4密碼模式
鏈接URL:http://www.dlmjj.cn/article/ghccid.html