1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

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

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      如何在Ocelot網(wǎng)關(guān)中實(shí)現(xiàn)IdentityServer4密碼模式
      本篇內(nèi)容介紹了“如何在Ocelot網(wǎng)關(guān)中實(shí)現(xiàn)IdentityServer4密碼模式”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

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

      概述

      成都創(chuàng)新互聯(lián)公司主營平潭網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app開發(fā)定制,平潭h5微信小程序開發(fā)搭建,平潭網(wǎng)站營銷推廣歡迎平潭等地區(qū)企業(yè)咨詢

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

      OAuth 2.0 默認(rèn)四種授權(quán)模式(GrantType):

      授權(quán)碼模式(authorization_code)

      簡化模式(implicit)

      密碼模式(password)

      客戶端模式(client_credentials)

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

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

      主要實(shí)現(xiàn)方式

      1、在認(rèn)證項(xiàng)目中,創(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,進(jìn)行賬號密碼認(rèn)證

      public class ResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator     {         public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)         {             //根據(jù)context.UserName和context.Password與數(shù)據(jù)庫的數(shù)據(jù)做校驗(yàn),判斷是否合法             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             {                 //驗(yàn)證失敗                 context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "invalid custom credential");             }         }     }

      3、調(diào)整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

      //注冊服務(wù)             var idResources = new List             {               new IdentityResources.OpenId(), //必須要添加,否則報(bào)無效的 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、在認(rèn)證項(xiàng)目進(jìn)行驗(yàn)證,測試成功

      6、修改地址,在網(wǎng)關(guān)項(xiàng)目進(jìn)行認(rèn)證,測試成功

      代碼地址:

      https://gitee.com/conanOpenSource_admin/Example


      網(wǎng)頁名稱:如何在Ocelot網(wǎng)關(guān)中實(shí)現(xiàn)IdentityServer4密碼模式
      分享網(wǎng)址:http://ef60e0e.cn/article/dpipi.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        阳城县| 台安县| 休宁县| 招远市| 山阳县| 大悟县| 滦南县| 梁平县| 衡阳县| 蒙城县| 那曲县| 岱山县| 瓦房店市| 安义县| 绍兴市| 新巴尔虎左旗| 松江区| 肃南| 大方县| 穆棱市| 开阳县| 本溪市| 高唐县| 临西县| 神池县| 新民市| 丰镇市| 九龙城区| 柳江县| 赣榆县| 沙河市| 保亭| 遂昌县| 普格县| 图木舒克市| 海伦市| 芒康县| 大冶市| 万年县| 安义县| 瓦房店市|