[英]How do I retrieve the JWT token in C#?
我從 AzureAD 中檢索了一個id_token
,我可以在檢查元素中看到它。
我只是想在 C# 中檢索令牌,這樣我就可以解密它,但我無法這樣做。
我試過了:
var authHeader = Request.Headers["id_token"];
var authHeader = Request.Form["id_token"];
JwtSecurityToken token = new JwtSecurityToken(authHeader);
兩者都返回空值。
您可以通過覆蓋OnSecurityTokenReceived
方法獲取 id 令牌。
將自定義OnSecurityTokenReceived
添加到Notifications
。
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = OnAuthenticationFailed,
SecurityTokenReceived= OnSecurityTokenReceived
}
然后你可以像這樣獲得id令牌
private Task OnSecurityTokenReceived(SecurityTokenReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> context)
{
var idtoken = context.ProtocolMessage.IdToken;
return Task.FromResult(0);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.