How to Retrieve id_token for End Session Endpoint in Duende IdentityServer v6.2.3 and Asp.Net Core 6.0 MVC?

huangapple go评论51阅读模式
英文:

How to Retrieve id_token for End Session Endpoint in Duende IdentityServer v6.2.3 and Asp.Net Core 6.0 MVC?

问题

我有一个使用Asp.Net Core 6.0 MVC应用程序,通过我们的Duende IdentityServer(v6.2.3)进行身份验证。当我想注销IdentityServer时,它要求调用结束会话端点。其中一个参数是id_token,需要这个令牌以便确定客户端。问题是,在身份验证时我没有得到id_token,那么我该如何获取它呢?感谢任何帮助。

客户端在IdentityServer中配置为“authorization_code”授权类型,OpenIdConnect ResponseType选项设置为“code”。我尝试将其更改为“code id_token”,但导致错误。

英文:

I have a Asp.Net Core 6.0 MVC app, which authenticates with our Duende IdentityServer (v6.2.3). When I want to logout of identityserver, it states that you must call the end session endpoint. One of the params is id_token, which is needed so it can determine the client. The thing is, I don't get an id_token when authenticating, so how can I get this? Appreciate any help.

The client is configured as 'authorization_code' grant type in identityserver, and OpenIdConnect ResponseType option is set to "code". I've tried changing this to 'code id_token', but this results in an error.

答案1

得分: 0

你应该在用户经过身份验证后始终收到一个ID令牌,如果你请求了openid范围并且响应模式是response_type=code。

也许ID令牌在身份验证后没有正确地被持久化(即记住)?

英文:

You should always receive an ID token after authenticating the user if you ask for the openid scope and the response mode is response_type=code.

Perhaps the id-token is not persisted properly (ie remembered) after authentication?

答案2

得分: 0

我没有意识到 id_token 包含在 cookie 的身份验证票据中。我只是添加了这段代码来检索它。

var properties = (await _contextAccessor.HttpContext?.AuthenticateAsync()!).Properties?.Items!;

if (properties != null && properties.TryGetValue(".Token.id_token", out var token))
   return token;

return null;
英文:

I didn't realise that the id_token was contained within the authentication ticket in the cookie. I just added this bit of code to retrieve it.

var properties = (await _contextAccessor.HttpContext?.AuthenticateAsync()!).Properties?.Items!;

if (properties != null && properties.TryGetValue(".Token.id_token", out var token))
   return token;

return null;

huangapple
  • 本文由 发表于 2023年6月1日 15:28:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76379580.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定