pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <bdo id='jiUg2'></bdo><ul id='jiUg2'></ul>

      1. <legend id='jiUg2'><style id='jiUg2'><dir id='jiUg2'><q id='jiUg2'></q></dir></style></legend>
        <tfoot id='jiUg2'></tfoot>

        <i id='jiUg2'><tr id='jiUg2'><dt id='jiUg2'><q id='jiUg2'><span id='jiUg2'><b id='jiUg2'><form id='jiUg2'><ins id='jiUg2'></ins><ul id='jiUg2'></ul><sub id='jiUg2'></sub></form><legend id='jiUg2'></legend><bdo id='jiUg2'><pre id='jiUg2'><center id='jiUg2'></center></pre></bdo></b><th id='jiUg2'></th></span></q></dt></tr></i><div class="aoaeygs" id='jiUg2'><tfoot id='jiUg2'></tfoot><dl id='jiUg2'><fieldset id='jiUg2'></fieldset></dl></div>
      2. <small id='jiUg2'></small><noframes id='jiUg2'>

        如何使用對稱密鑰配置 Microsoft JWT?

        How to configure Microsoft JWT with symmetric key?(如何使用對稱密鑰配置 Microsoft JWT?)
          <i id='sKrFe'><tr id='sKrFe'><dt id='sKrFe'><q id='sKrFe'><span id='sKrFe'><b id='sKrFe'><form id='sKrFe'><ins id='sKrFe'></ins><ul id='sKrFe'></ul><sub id='sKrFe'></sub></form><legend id='sKrFe'></legend><bdo id='sKrFe'><pre id='sKrFe'><center id='sKrFe'></center></pre></bdo></b><th id='sKrFe'></th></span></q></dt></tr></i><div class="ykwiaam" id='sKrFe'><tfoot id='sKrFe'></tfoot><dl id='sKrFe'><fieldset id='sKrFe'></fieldset></dl></div>
            <tbody id='sKrFe'></tbody>

          • <bdo id='sKrFe'></bdo><ul id='sKrFe'></ul>

                <legend id='sKrFe'><style id='sKrFe'><dir id='sKrFe'><q id='sKrFe'></q></dir></style></legend><tfoot id='sKrFe'></tfoot>

                1. <small id='sKrFe'></small><noframes id='sKrFe'>

                  本文介紹了如何使用對稱密鑰配置 Microsoft JWT?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在嘗試將我的 ASP.NET 應用程序配置為接受使用對稱密鑰簽名的 JSON Web 令牌 (JWT).STS 無法為此使用證書,因此我們正在使用它們的對稱密鑰支持.

                  I'm trying to configure my ASP.NET app to accept a JSON Web Token (JWT) that is signed with a symmetric key. The STS isn't capable of using certificates for this, so we're using their symmetric key support.

                  就我而言,我正在使用 微軟的 JWT 開發者預覽版.不幸的是,我還沒有看到任何關于如何將其與對稱密鑰一起使用的示例.在使用各種工具進行了一些挖掘之后,我找到了 NamedKeyIssuerTokenResolver 并發現我可以 將其配置為使用對稱密鑰.例如:

                  On my end, I'm using Microsoft's JWT Developer Preview. Unfortunately, I've not seen any examples of how to use that with a symmetric key. After some digging around with various tools, I found the NamedKeyIssuerTokenResolver and discovered that I can configure it to use a symmetric key. For example:

                  <securityTokenHandlers>
                    <add type="Microsoft.IdentityModel.Tokens.JWT.JWTSecurityTokenHandler,Microsoft.IdentityModel.Tokens.JWT" />
                    <securityTokenHandlerConfiguration>
                      <certificateValidation certificateValidationMode="PeerTrust" />
                      <issuerTokenResolver
                        type="Microsoft.IdentityModel.Tokens.JWT.NamedKeyIssuerTokenResolver,
                          Microsoft.IdentityModel.Tokens.JWT">
                        <securityKey
                            symmetricKey="+zqf97FD/xyzzyplugh42ploverFeeFieFoeFooxqjE="
                               name="https://localhost/TestRelyingParty" />
                      </issuerTokenResolver>
                    </securityTokenHandlerConfiguration>
                  </securityTokenHandlers>
                  

                  我不完全確定我應該為那里的 name 使用什么.應該是受眾Uri,還是發行者Uri?無論如何,我知道如果我不包含 name,我的程序啟動時會出現異常,因為 securityKey 元素需要該屬性.

                  I'm not entirely sure what I'm supposed to use for the name there. Should it be the audience Uri, perhaps the issuer Uri? In any case, I know that if I don't include a name, I get an exception when my program starts because the securityKey element requires that attribute.

                  無論如何,這仍然不能解決問題.對 STS 進行身份驗證后,出現以下異常:

                  Whatever the case, this still doesn't resolve the issue. After I authenticate against the STS, I get the following exception:

                  [SecurityTokenValidationException: JWT10310: Unable to validate signature. validationParameters.SigningTokenResolver type: 'Microsoft.IdentityModel.Tokens.JWT.NamedKeyIssuerTokenResolver', was unable to resolve key to a token.
                  The SecurityKeyIdentifier is: 
                  'SecurityKeyIdentifier
                      (
                      IsReadOnly = False,
                      Count = 1,
                      Clause[0] = Microsoft.IdentityModel.Tokens.JWT.NamedKeyIdentifierClause
                      )
                  '. validationParameters.SigningToken was null.]
                     Microsoft.IdentityModel.Tokens.JWT.JWTSecurityTokenHandler.ValidateSignature(JWTSecurityToken jwt, TokenValidationParameters validationParameters) +2111
                     Microsoft.IdentityModel.Tokens.JWT.JWTSecurityTokenHandler.ValidateToken(JWTSecurityToken jwt, TokenValidationParameters validationParameters) +138
                     Microsoft.IdentityModel.Tokens.JWT.JWTSecurityTokenHandler.ValidateToken(SecurityToken token) +599
                     System.IdentityModel.Tokens.SecurityTokenHandlerCollection.ValidateToken(SecurityToken token) +135
                     System.IdentityModel.Services.TokenReceiver.AuthenticateToken(SecurityToken token, Boolean ensureBearerToken, String endpointUri) +117
                     System.IdentityModel.Services.WSFederationAuthenticationModule.SignInWithResponseMessage(HttpRequestBase request) +698
                     System.IdentityModel.Services.WSFederationAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs args) +123924
                     System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
                     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165
                  

                  我是否缺少其他配置步驟?我在 name 屬性中放置了錯誤的東西嗎?或者這是 JWT 開發者預覽版中的一個已知錯誤?

                  Am I missing some other configuration step? Am I putting the wrong thing in the name attribute? Or is this a known bug in the JWT Developer Preview?

                  推薦答案

                  2014/02/13 更新:

                  正如@leastprivilege 在下面指出的那樣,使用 JWT 的 RTM 版本要容易得多.我強烈建議您忽略這一點并使用他在 http://leastprivilege.com/2013/07/16/identityserver-using-ws-federation-with-jwt-tokens-and-symmetric-signatures/.

                  請注意,下面的原始答案是針對 Beta 版 Microsoft.IdentityModel.Tokens.JWT.升級到發布版本 System.IdentityModel.Tokens.Jwt 只需要多做一點工作.見下文.

                  Note that the original answer below was for the Beta version, Microsoft.IdentityModel.Tokens.JWT. Upgrading to the release version, System.IdentityModel.Tokens.Jwt, required just a little more work. See below.

                  原來的主要問題是 JWTSecurityTokenHandler.ValidateToken(token) 方法沒有完全填充它傳遞給 JWTSecurityTokenHandler.ValidateToken(令牌,驗證參數).特別是,它不會填充 SigningToken 成員或 ValidIssuers(或 ValidIssuer).

                  The primary problem turns out to be that the method JWTSecurityTokenHandler.ValidateToken(token) does not fully populate the TokenValidationParameters that it passes to JWTSecurityTokenHandler.ValidateToken(token, validationParameters). In particular, it doesn't populate the SigningToken member or the ValidIssuers (or ValidIssuer).

                  有趣的是,我在原始問題中顯示的配置實際上是由令牌解析器加載的,并且在運行時可用,如下面的代碼所示.

                  Interestingly, the configuration I showed in my original question actually is loaded by the token resolver, and is available at runtime, as you can see in the code below.

                  不過,我不知道如何在配置文件中指定有效的頒發者字符串.我強烈懷疑有一個地方可以放置這些信息,但我還沒有弄清楚它屬于哪里.

                  I don't know how to specify the valid issuer string in the configuration file, though. I strongly suspect that there's a place to put that info, but I haven't yet figured out where it belongs.

                  我的問題的解決方案是創建一個從 JWTSecurityTokenHandler 派生的自定義安全令牌處理程序.重寫 ValidateToken(token, validationParameters) 讓我有機會設置我需要的那些參數,然后調用基類的 ValidateToken 方法.

                  The solution to my problem is to create a custom security token handler that derives from JWTSecurityTokenHandler. Overriding ValidateToken(token, validationParameters) gives me the opportunity to set those parameters that I need, and then call the base class's ValidateToken method.

                  public class CustomJwtSecurityTokenHandler: JWTSecurityTokenHandler
                  {
                      // Override ValidateSignature so that it gets the SigningToken from the configuration if it doesn't exist in
                      // the validationParameters object.
                      private const string KeyName = "https://localhost/TestRelyingParty";
                      private const string ValidIssuerString = "https://mySTSname/trust";
                      public override ClaimsPrincipal ValidateToken(JWTSecurityToken jwt, TokenValidationParameters validationParameters)
                      {
                          // set up valid issuers
                          if ((validationParameters.ValidIssuer == null) &&
                              (validationParameters.ValidIssuers == null || !validationParameters.ValidIssuers.Any()))
                          {
                              validationParameters.ValidIssuers = new List<string> {ValidIssuerString};
                          }
                          // and signing token.
                          if (validationParameters.SigningToken == null)
                          {
                              var resolver = (NamedKeyIssuerTokenResolver)this.Configuration.IssuerTokenResolver;
                              if (resolver.SecurityKeys != null)
                              {
                                  List<SecurityKey> skeys;
                                  if (resolver.SecurityKeys.TryGetValue(KeyName, out skeys))
                                  {
                                      var tok = new NamedKeySecurityToken(KeyName, skeys);
                                      validationParameters.SigningToken = tok;
                                  }
                              }
                          }
                          return base.ValidateToken(jwt, validationParameters);
                      }
                  }
                  

                  在我的 Web.config 中,我只需要更改安全令牌處理程序:

                  In my Web.config, I just had to change the security token handler:

                    <securityTokenHandlers>
                      <!--<add type="Microsoft.IdentityModel.Tokens.JWT.JWTSecurityTokenHandler,Microsoft.IdentityModel.Tokens.JWT" />-->
                      <!-- replaces the default JWTSecurityTokenHandler -->
                      <add type="TestRelyingParty.CustomJwtSecurityTokenHandler,TestRelyingParty" />
                  

                  沒有什么比花三四天時間研究一個用幾十行代碼解決的問題更合適的了...

                  Nothing like spending three or four days researching a problem that is solved with a couple dozen lines of code . . .

                  2013 年 6 月,微軟正式發布了他們的 JWT.他們將命名空間更改為 System.IdentityModel.Tokens.Jwt.升級到那個之后,上面的解決方案停止工作.為了讓它工作,我必須將以下內容添加到我的 CustomJwtSecurityTokenHandler 中.這是對現有代碼的補充.

                  In June of 2013, Microsoft officially released their JWT. They changed the namespace to System.IdentityModel.Tokens.Jwt. After upgrading to that, the solution above stopped working. To get it working, I had to add the following to my CustomJwtSecurityTokenHandler. That's in addition to the existing code.

                  public override ClaimsPrincipal ValidateToken(JwtSecurityToken jwt)
                  {
                      var vparms = new TokenValidationParameters
                          {
                              AllowedAudiences = Configuration.AudienceRestriction.AllowedAudienceUris.Select(s => s.ToString())
                          };
                      return ValidateToken(jwt, vparms);
                  }
                  

                  這篇關于如何使用對稱密鑰配置 Microsoft JWT?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數調用按鈕 OnClick)
                  ASP.net C# Gridview ButtonField onclick event(ASP.net C# Gridview ButtonField onclick 事件)
                  Adding OnClick event to ASP.NET control(將 OnClick 事件添加到 ASP.NET 控件)
                  Multiple submit Button click problem?(多個提交按鈕點擊問題?)

                      <tbody id='oWIc6'></tbody>
                    <tfoot id='oWIc6'></tfoot>

                    <small id='oWIc6'></small><noframes id='oWIc6'>

                      <legend id='oWIc6'><style id='oWIc6'><dir id='oWIc6'><q id='oWIc6'></q></dir></style></legend>

                          <bdo id='oWIc6'></bdo><ul id='oWIc6'></ul>

                          <i id='oWIc6'><tr id='oWIc6'><dt id='oWIc6'><q id='oWIc6'><span id='oWIc6'><b id='oWIc6'><form id='oWIc6'><ins id='oWIc6'></ins><ul id='oWIc6'></ul><sub id='oWIc6'></sub></form><legend id='oWIc6'></legend><bdo id='oWIc6'><pre id='oWIc6'><center id='oWIc6'></center></pre></bdo></b><th id='oWIc6'></th></span></q></dt></tr></i><div class="q0wikcy" id='oWIc6'><tfoot id='oWIc6'></tfoot><dl id='oWIc6'><fieldset id='oWIc6'></fieldset></dl></div>

                            主站蜘蛛池模板: PC构件-PC预制构件-构件设计-建筑预制构件-PC构件厂-锦萧新材料科技(浙江)股份有限公司 | 反渗透水处理设备|工业零排放|水厂设备|软化水设备|海南净水设备--海南水处理设备厂家 | 东莞市超赞电子科技有限公司 全系列直插/贴片铝电解电容,电解电容,电容器 | 渣土车电机,太阳能跟踪器电机,蜗轮蜗杆减速电机厂家-淄博传强电机 | 博医通医疗器械互联网供应链服务平台_博医通 | 宁夏活性炭_防护活性炭_催化剂载体炭-宁夏恒辉活性炭有限公司 | Eiafans.com_环评爱好者 环评网|环评论坛|环评报告公示网|竣工环保验收公示网|环保验收报告公示网|环保自主验收公示|环评公示网|环保公示网|注册环评工程师|环境影响评价|环评师|规划环评|环评报告|环评考试网|环评论坛 - Powered by Discuz! | 陕西高职单招-陕西高职分类考试网 | 济南网站建设_济南网站制作_济南网站设计_济南网站建设公司_富库网络旗下模易宝_模板建站 | 硬质合金模具_硬质合金非标定制_硬面加工「生产厂家」-西迪技术股份有限公司 | 心得体会网_心得体会格式范文模板 | 烟气在线监测系统_烟气在线监测仪_扬尘检测仪_空气质量监测站「山东风途物联网」 | 扫地车厂家-山西洗地机-太原电动扫地车「大同朔州吕梁晋中忻州长治晋城洗地机」山西锦力环保科技有限公司 | 美侍宠物-专注宠物狗及宠物猫训练|喂养|医疗|繁育|品种|价格 | 冻干机(冷冻干燥机)_小型|实验型|食品真空冷冻干燥机-松源 | 盛源真空泵|空压机-浙江盛源空压机制造有限公司-【盛源官网】 | 菏泽知彼网络科技有限公司 | 湖州织里童装_女童男童中大童装_款式多尺码全_织里儿童网【官网】-嘉兴嘉乐网络科技有限公司 | 多米诺-多米诺世界纪录团队-多米诺世界-多米诺团队培训-多米诺公关活动-多米诺创意广告-多米诺大型表演-多米诺专业赛事 | 拉力测试机|材料拉伸试验机|电子拉力机价格|万能试验机厂家|苏州皖仪实验仪器有限公司 | 浙江栓钉_焊钉_剪力钉厂家批发_杭州八建五金制造有限公司 | 防爆暖风机_防爆电暖器_防爆电暖风机_防爆电热油汀_南阳市中通智能科技集团有限公司 | 天津热油泵_管道泵_天津高温热油泵-天津市金丰泰机械泵业有限公司【官方网站】 | 全自动五线打端沾锡机,全自动裁线剥皮双头沾锡机,全自动尼龙扎带机-东莞市海文能机械设备有限公司 | 天一线缆邯郸有限公司_煤矿用电缆厂家_矿用光缆厂家_矿用控制电缆_矿用通信电缆-天一线缆邯郸有限公司 | TYPE-C厂家|TYPE-C接口|TYPE-C防水母座|TYPE-C贴片-深圳步步精 | 东莞画册设计_logo/vi设计_品牌包装设计 - 华略品牌设计公司 | 番茄畅听邀请码怎么输入 - Dianw8.com | 餐饮加盟网_特色餐饮加盟店_餐饮连锁店加盟 | 北京律师事务所_房屋拆迁律师_24小时免费法律咨询_云合专业律师网 | 丝杆升降机-不锈钢丝杆升降机-非标定制丝杆升降机厂家-山东鑫光减速机有限公司 | 企业彩铃制作_移动、联通、电信集团彩铃上传开通_彩铃定制_商务彩铃管理平台-集团彩铃网 | 成人纸尿裤,成人尿不湿,成人护理垫-山东康舜日用品有限公司 | 中国产业发展研究网 - 提供行业研究报告 可行性研究报告 投资咨询 市场调研服务 | 上海办公室装修_上海店铺装修公司_厂房装潢设计_办公室装修 | 隔离变压器-伺服变压器--输入输出电抗器-深圳市德而沃电气有限公司 | 折弯机-刨槽机-数控折弯机-数控刨槽机-数控折弯机厂家-深圳豐科机械有限公司 | 测试治具|过炉治具|过锡炉治具|工装夹具|测试夹具|允睿自动化设备 | 磁力轮,磁力联轴器,磁齿轮,钕铁硼磁铁-北京磁运达厂家 | 华禹护栏|锌钢护栏_阳台护栏_护栏厂家-华禹专注阳台护栏、楼梯栏杆、百叶窗、空调架、基坑护栏、道路护栏等锌钢护栏产品的生产销售。 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 |