我已经在 IdentityServer 4 中实现了IDP.我的Web应用程序客户端(在Mvc 5中实现)通过IDP进行身份验证,但现在我需要从请求中获取访问令牌. 在.Net Core中执行此操作的一种方法是使用 Microsoft.AspNetCore.Authentication.AuthenticationTokenExtensions 像这样:
I've got a IDP implemented in IdentityServer 4. My web app client(implemented in Mvc 5) authenticates with the IDP but now I need to get the access token from the request. A way to do that in .Net Core is to use the Microsoft.AspNetCore.Authentication.AuthenticationTokenExtensions like so:
HttpContext.Authentication.GetTokenAsync("acccess_token")我希望能够在 Mvc5 Web应用程序客户端中执行相同的操作,但是找不到具有类似实现的任何nuget包或名称空间.能够在MVC5中而不是 Core中执行此操作很重要.有人遇到过这个吗?
I would like to be able to do the same in my Mvc5 web app client but I can't find any nuget package or namespace that has a similar implementation. It is important to be able to do this in MVC5 and not Core. Anyone came across this before?
PS-还值得一提的是,我正在使用OpenIdConnect
PS- Also worth to mention that I'm using OpenIdConnect
推荐答案最近发布的 Katana的4.1.0版本现在支持 SaveTokens属性(从ASP.NET Core反向移植).
The recently released 4.1.0 version of Katana now supports the SaveTokens property (backported from ASP.NET Core).
为了获取访问令牌:
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions { // Other options removed for readability SaveTokens = true, // Required for the authorization code flow to exchange for tokens automatically RedeemCode = true });
var result = await Request.GetOwinContext().Authentication.AuthenticateAsync("Cookies"); string token = result.Properties.Dictionary["access_token"];
更多推荐
如何使用owin和Mvc 5从httpcontext获取访问令牌
发布评论