久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <tfoot id='IYhcE'></tfoot>
  2. <i id='IYhcE'><tr id='IYhcE'><dt id='IYhcE'><q id='IYhcE'><span id='IYhcE'><b id='IYhcE'><form id='IYhcE'><ins id='IYhcE'></ins><ul id='IYhcE'></ul><sub id='IYhcE'></sub></form><legend id='IYhcE'></legend><bdo id='IYhcE'><pre id='IYhcE'><center id='IYhcE'></center></pre></bdo></b><th id='IYhcE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IYhcE'><tfoot id='IYhcE'></tfoot><dl id='IYhcE'><fieldset id='IYhcE'></fieldset></dl></div>
    <legend id='IYhcE'><style id='IYhcE'><dir id='IYhcE'><q id='IYhcE'></q></dir></style></legend>
  3. <small id='IYhcE'></small><noframes id='IYhcE'>

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

      驗(yàn)證 AspNet.Security.OpenIdConnect.Server (ASP.NET vNext) 頒

      Validating Tokens Issued by AspNet.Security.OpenIdConnect.Server (ASP.NET vNext)(驗(yàn)證 AspNet.Security.OpenIdConnect.Server (ASP.NET vNext) 頒發(fā)的令牌)
      <legend id='Sdzq1'><style id='Sdzq1'><dir id='Sdzq1'><q id='Sdzq1'></q></dir></style></legend>
        <tbody id='Sdzq1'></tbody>

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

        • <tfoot id='Sdzq1'></tfoot>
              <bdo id='Sdzq1'></bdo><ul id='Sdzq1'></ul>
            • <small id='Sdzq1'></small><noframes id='Sdzq1'>

              • 本文介紹了驗(yàn)證 AspNet.Security.OpenIdConnect.Server (ASP.NET vNext) 頒發(fā)的令牌的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                限時送ChatGPT賬號..

                我正在使用 Visual Studio 2015 Enterprise 和 ASP.NET vNext Beta8 來構(gòu)建一個端點(diǎn),該端點(diǎn)發(fā)出并使用 JWT 令牌.我最初是通過自己生成令牌來解決這個問題的,如 所述這里.后來@Pinpoint 的一篇有用的文章顯示,AspNet.Security.OpenIdConnect.Server(又名 OIDC)可以配置為為我發(fā)放和使用令牌.

                I am using Visual Studio 2015 Enterprise and ASP.NET vNext Beta8 to build an endpoint that both issues and consumes JWT tokens. I Originally approached this by generating the tokens myself, as described here. Later a helpful article by @Pinpoint revealed that AspNet.Security.OpenIdConnect.Server (a.k.a. OIDC) can be configured to issue and consume the tokens for me.

                所以我按照這些說明,建立了一個端點(diǎn),并從 郵遞員 我收到了一個合法的令牌:

                So I followed those instructions, stood up an endpoint, and by submitting an x-www-form-urlencoded post from postman I receive back a legit token:

                {
                  "token_type": "bearer",
                  "access_token": "eyJ0eXAiO....",
                  "expires_in": "3599"
                }
                

                這很棒,但也是我卡住的地方.現(xiàn)在,我如何注釋控制器操作以使其需要此不記名令牌?

                This is great but also where I get stuck. Now, how do I annotate a controller action so that it demands this bearer token?

                我以為我要做的就是用[Authorize("Bearer")],添加認(rèn)證方案:

                I thought all I would have to do is decorate my controller method with the [Authorize("Bearer")], add an authentication scheme:

                        services.AddAuthorization
                        (
                            options => 
                            {
                                options.AddPolicy
                                (
                                    JwtBearerDefaults.AuthenticationScheme, 
                                    builder => 
                                    {
                                        builder.
                                        AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme).
                                        RequireAuthenticatedUser().
                                        Build();
                                    } 
                                );
                            }
                        );
                

                然后像我在前面的示例中所做的那樣,使用Authorization Bearer eyJ0eXAiO...."標(biāo)題調(diào)用我的控制器操作.可悲的是,所有這些方法似乎都會產(chǎn)生一個異常:

                And then call my controller action with the "Authorization bearer eyJ0eXAiO...." header as I had done in my previous example. Sadly, all this approach seems to do though is generate an exception:

                處理請求時發(fā)生未處理的異常.

                An unhandled exception occurred while processing the request.

                SocketException: 無法建立連接,因?yàn)槟繕?biāo)機(jī)器主動拒絕了它 127.0.0.1:50000

                SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:50000

                WebException: 無法連接到遠(yuǎn)程服務(wù)器

                WebException: Unable to connect to the remote server

                HttpRequestException: 發(fā)送請求時出錯.

                HttpRequestException: An error occurred while sending the request.

                IOException:IDX10804:無法從以下位置檢索文檔:'http://localhost:50000/.well-known/openid-configuration'.Microsoft.IdentityModel.Logging.LogHelper.Throw(String message, Type exceptionType, EventLevel logLevel, Exception innerException)

                IOException: IDX10804: Unable to retrieve document from: 'http://localhost:50000/.well-known/openid-configuration'. Microsoft.IdentityModel.Logging.LogHelper.Throw(String message, Type exceptionType, EventLevel logLevel, Exception innerException)

                InvalidOperationException: IDX10803: Unable to get configuration from: 'http://localhost:50000/.well-known/openid-configuration'.內(nèi)部異常:'IDX10804:無法從以下位置檢索文檔:'http://localhost:50000/.well-known/openid-configuration'.'.

                InvalidOperationException: IDX10803: Unable to obtain configuration from: 'http://localhost:50000/.well-known/openid-configuration'. Inner Exception: 'IDX10804: Unable to retrieve document from: 'http://localhost:50000/.well-known/openid-configuration'.'.


                考慮以下步驟來重現(xiàn)(但請不要考慮這個生產(chǎn)有價值的代碼):


                Consider the following steps to reproduce (but please don't consider this production worthy code):

                • 按照描述應(yīng)用 ASP.NET Beta8 工具 這里

                打開 Visual Studio Enterprise 2015 并創(chuàng)建一個新的 Web API ASP.NET 5 Preview Template 項(xiàng)目

                Open Visual Studio Enterprise 2015 and create a new Web API ASP.NET 5 Preview Template project

                更改 project.json

                Change project.json

                {
                "webroot": "wwwroot",
                "版本": "1.0.0-*",

                依賴":{
                "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
                "Microsoft.AspNet.Mvc": "6.0.0-beta8",
                "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
                "Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-beta8",
                "AspNet.Security.OpenIdConnect.Server": "1.0.0-beta3",
                "Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-beta8",
                "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
                "Microsoft.AspNet.Diagnostics": "1.0.0-beta8"
                },

                命令":{
                "web": "Microsoft.AspNet.Server.Kestrel"
                },

                框架":{
                dnx451":{ }
                },

                排除":[
                "wwwroot",
                節(jié)點(diǎn)模塊"
                ],
                發(fā)布排除":[
                ".user",
                "
                .vspscc"
                ]
                }

                {
                "webroot": "wwwroot",
                "version": "1.0.0-*",

                "dependencies": {
                "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
                "Microsoft.AspNet.Mvc": "6.0.0-beta8",
                "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
                "Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-beta8",
                "AspNet.Security.OpenIdConnect.Server": "1.0.0-beta3",
                "Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-beta8",
                "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4",
                "Microsoft.AspNet.Diagnostics": "1.0.0-beta8"
                },

                "commands": {
                "web": "Microsoft.AspNet.Server.Kestrel"
                },

                "frameworks": {
                "dnx451": { }
                },

                "exclude": [
                "wwwroot",
                "node_modules"
                ],
                "publishExclude": [
                ".user",
                "
                .vspscc"
                ]
                }

                如下更改 Startup.cs(這是@Pinpoint 的原始文章提供的;我已刪除評論并添加了 AddAuthorization snip):

                Change Startup.cs as follows (this is courtesy of @Pinpoint's original article; I have removed comments and added the AddAuthorization snip):

                public class Startup
                {
                    public Startup(IHostingEnvironment env)
                    {
                    }
                
                    public void ConfigureServices(IServiceCollection services)
                    {
                        services.AddAuthorization
                        (
                            options => 
                            {
                                options.AddPolicy
                                (
                                    JwtBearerDefaults.AuthenticationScheme, 
                                    builder => 
                                    {
                                        builder.
                                        AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme).
                                        RequireAuthenticatedUser().
                                        Build();
                                    } 
                                );
                            }
                        );
                        services.AddAuthentication();
                        services.AddCaching();
                        services.AddMvc();
                        services.AddOptions();
                    }
                
                    // Configure is called after ConfigureServices is called.
                    public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions<AppSettings> appSettings)
                    {
                        app.UseDeveloperExceptionPage();
                
                        // Add a new middleware validating access tokens issued by the OIDC server.
                        app.UseJwtBearerAuthentication(options => {
                            options.AutomaticAuthentication = true;
                            options.Audience = "http://localhost:50000/";
                            options.Authority = "http://localhost:50000/";
                            options.ConfigurationManager = new ConfigurationManager<OpenIdConnectConfiguration>
                            (
                                metadataAddress : options.Authority + ".well-known/openid-configuration",
                                configRetriever : new OpenIdConnectConfigurationRetriever(),
                                docRetriever    : new HttpDocumentRetriever { RequireHttps = false }
                            );
                        });
                
                        // Add a new middleware issuing tokens.
                        app.UseOpenIdConnectServer
                        (
                            configuration => 
                            {
                                configuration.Options.TokenEndpointPath= "/authorization/v1";
                                configuration.Options.AllowInsecureHttp = true;
                                configuration.Provider = new OpenIdConnectServerProvider {
                
                                    OnValidateClientAuthentication = context => 
                                    {
                                        context.Skipped();
                                        return Task.FromResult<object>(null);
                                    },
                
                                    OnGrantResourceOwnerCredentials = context => 
                                    {
                                        var identity = new ClaimsIdentity(OpenIdConnectDefaults.AuthenticationScheme);
                                        identity.AddClaim( new Claim(ClaimTypes.NameIdentifier, "todo")  );
                                        identity.AddClaim( new Claim("urn:customclaim", "value", "token id_token"));
                                        context.Validated(new ClaimsPrincipal(identity));
                                        return Task.FromResult<object>(null);
                                    }
                                };
                            }
                        );
                
                        app.UseMvc();
                    }
                }
                

                • 更改 Wizarded ValuesController.cs 以指定 Authorize 屬性:
                • [Route("api/[controller]")]
                  public class ValuesController : Controller
                  {
                      // GET: api/values
                      [Authorize("Bearer")] 
                      [HttpGet]
                      public IEnumerable<string> Get()
                      {
                          return new string[] { "value1", "value2" };
                      }
                  }
                  

                  • 運(yùn)行項(xiàng)目,并使用 postman 獲取令牌.要獲取令牌,請使用 x-www-form-urlencoded POST,其中g(shù)rant_type"為password",username"為任何內(nèi)容,password"為任何內(nèi)容,resource"為 API 端點(diǎn)的地址.例如,我的特定 URL 是 http://localhost:37734/authorization/v1.

                    • Run the project, and acquire a token using postman. To acquire a token use x-www-form-urlencoded POST with "grant_type" of "password", "username" anything, "password" anything and "resource" the address of the API endpoint. My particular URL for example is http://localhost:37734/authorization/v1.

                      復(fù)制 Base64 編碼的令牌,然后使用令牌通過 郵遞員.要使用令牌,請使用標(biāo)頭 Content-Type application/json 和 Authorization Bearer eyJ0eXAiO....(您的令牌)進(jìn)行 GET.我的特定 URL 是 http://localhost:37734/api/values.

                      Copy the Base64 encoded token, then use the token to call the wizarded values controller using postman. To use the token make a GET with the headers Content-Type application/json and Authorization bearer eyJ0eXAiO....(your token). My particular URL is http://localhost:37734/api/values.

                      注意前面提到的異常.

                      如果我在上面嘗試的 [Authorize("Bearer")] 方法是錯誤的方法,如果有人能幫助我了解如何使用 OIDC 攝取 JWT 令牌的最佳實(shí)踐,我將非常感激.

                      If the [Authorize("Bearer")] approach I'm trying above is the wrong way to go I would be very appreciative if someone could help me understand best practices for how to ingest the JWT token using OIDC.

                      謝謝.

                      推薦答案

                      options.Authority對應(yīng)issuer地址(即你的OIDC服務(wù)器地址).

                      options.Authority corresponds to the issuer address (i.e the address of your OIDC server).

                      http://localhost:50000/ 似乎不正確,因?yàn)槟院笤趩栴}中使用 http://localhost:37734/ .嘗試修復(fù) URL,然后再試一次.

                      http://localhost:50000/ doesn't seem to be correct as you're using http://localhost:37734/ later in your question. Try fixing the URL and give it another try.

                      這篇關(guān)于驗(yàn)證 AspNet.Security.OpenIdConnect.Server (ASP.NET vNext) 頒發(fā)的令牌的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                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(從函數(shù)調(diào)用按鈕 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?(多個提交按鈕點(diǎn)擊問題?)

                  <tbody id='ZLU3z'></tbody>
                <tfoot id='ZLU3z'></tfoot>
              • <legend id='ZLU3z'><style id='ZLU3z'><dir id='ZLU3z'><q id='ZLU3z'></q></dir></style></legend>

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

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

                          主站蜘蛛池模板: 成人美女免费网站视频 | 久久国产成人 | 日韩在线播放中文字幕 | 国产日韩欧美精品一区二区三区 | 亚洲天堂av网| 亚洲一区二区三区四区五区中文 | 久久久久久国产精品 | 午夜精品久久久久久久久久久久 | www.久 | 久久久久国产一区二区 | 婷婷免费视频 | 国产日韩一区二区三免费高清 | 亚洲国产欧美国产综合一区 | 激情五月婷婷综合 | 91xxx在线观看 | 欧美日韩在线免费观看 | 国产精品久久久久久久久久免费看 | 国产综合久久久久久鬼色 | 国产一区二区精品在线观看 | 香蕉久久久 | www.天堂av.com | 国产午夜亚洲精品不卡 | 亚洲中国字幕 | 国产免费视频 | 日韩综合在线 | 日韩一区二区三区视频 | 人人操日日干 | 成人二区| 欧美日本在线 | 特级生活片 | 欧美黄色小视频 | 伊人网综合在线 | av片在线观看网站 | av一区二区三区 | 久久久久国产精品一区 | 亚洲精品黄色 | 日韩一区二区福利视频 | 欧美国产中文 | 国产精品久久九九 | 欧美男人天堂 | 午夜资源|