題我們?nèi)绾问褂糜脩裘兔艽a流在ASP.NET 5中使用持票令牌?對(duì)于我們的場(chǎng)景,我們希望讓用戶使用AJAX調(diào)用進(jìn)行注冊(cè)和登錄,而無需使用外部登錄。為此,我們需要一個(gè)授權(quán)服務(wù)器端點(diǎn)。在以前的ASP.NET版本中,我們將執(zhí)行以下操作,然后在ourdomain.com/TokenURL上登錄。// Configure the application for OAuth based flowPublicClientId = "self";OAuthOptions = new OAuthAuthorizationServerOptions{ TokenEndpointPath = new PathString("/Token"), Provider = new ApplicationOAuthProvider(PublicClientId), AccessTokenExpireTimeSpan = TimeSpan.FromDays(14)};但是,在當(dāng)前版本的ASP.NET中,上述操作無效。我們一直試圖找出新的方法。例如,GitHub上的aspnet / identity示例配置了Facebook,Google和Twitter身份驗(yàn)證,但似乎沒有配置非外部OAuth授權(quán)服務(wù)器端點(diǎn),除非這樣AddDefaultTokenProviders()做,在這種情況下我們想知道到底是什么URL提供者會(huì)。研究我們從閱讀源代碼中了解到,我們可以通過調(diào)用IAppBuilder.UseOAuthBearerAuthentication我們的Startup類來向HTTP管道添加“承載認(rèn)證中間件” 。雖然我們?nèi)匀徊淮_定如何設(shè)置其令牌端點(diǎn),但這是一個(gè)良好的開端。這不起作用:public void Configure(IApplicationBuilder app){ app.UseOAuthBearerAuthentication(options => { options.MetadataAddress = "meta"; }); // if this isn't here, we just get a 404 app.Run(async context => { await context.Response.WriteAsync("Hello World."); });}要去ourdomain.com/meta我們剛剛收到我們的Hello World頁面。進(jìn)一步的研究表明,我們也可以使用IAppBuilder.UseOAuthAuthentication擴(kuò)展方法,并且它需要一個(gè)OAuthAuthenticationOptions參數(shù)。該參數(shù)具有TokenEndpoint屬性。因此,雖然我們不確定我們?cè)谧鍪裁矗覀儑L試了這一點(diǎn),當(dāng)然這不起作用。public void Configure(IApplicationBuilder app){ app.UseOAuthAuthentication("What is this?", options => { options.TokenEndpoint = "/token"; options.AuthorizationEndpoint = "/oauth"; options.ClientId = "What is this?"; options.ClientSecret = "What is this?"; options.SignInScheme = "What is this?"; options.AutomaticAuthentication = true; }); // if this isn't here, we just get a 404 app.Run(async context => { await context.Response.WriteAsync("Hello World."); });}換句話說,在去ourdomain.com/token,沒有錯(cuò)誤,只有我們的問候世界頁面。
- 2 回答
- 0 關(guān)注
- 704 瀏覽
添加回答
舉報(bào)
0/150
提交
取消