gpt4 book ai didi

azure - 从 Azure Active Directory AuthenticationResult.AccessToken 获取 NameIdentifier

转载 作者:行者123 更新时间:2023-12-03 01:53:45 24 4
gpt4 key购买 nike

我需要从 Azure AD 发送的 token 中获取 nameidentifier。我假设这对于 AD 的每个用户来说都是唯一的,并且有一些基于它的自定义授权逻辑。例如,

AuthenticationResult result = authenticationContext.AcquireToken(webApiResourceId, certificateCredential);
string accessToken = result.AccessToken;

此 accessToken 作为 AuthenticationHeader 发送到 WebAPI,WebAPI 对其进行解密并获取 nameidentifier 作为

Claim tenantClaim = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier);

但是 WebAPI 上的这个过程是透明的,并且由 ADAL 执行。但是,我需要在客户端本身获取 NameIdentifier。有什么方法可以通过解密 AccessToken 在客户端本身获取 NameIdentifier 吗?我搜索后似乎没有找到正确的答案。

最佳答案

您能否详细说明为什么在客户端上需要 NameIdentifier?请注意,客户端不会对 token 执行任何验证,因此您不应根据 token 内容在客户端上做出任何访问控制决策。鉴于 token 本身在将其内容提供给应用程序之前经过验证,服务器端可以根据 token 内容做出决策。另一个重要的考虑因素:访问 token 适用于 Web API,客户端不应尝试读取它。即使您设法阅读它,您也会生成极其脆弱的逻辑,因为格式可以随时更改,它可能使用客户端不应该拥有的 key 进行加密,等等。如果出于不同原因需要访问客户端上的 NameIdentifier,您可以检查 id_token。 id token 是与访问 token 一起发送的另一个 token 。 id token 是供客户端使用的,因此您查看它是安全的。您可以在 AuthenticationResult 中找到它作为属性。华泰五、

关于azure - 从 Azure Active Directory AuthenticationResult.AccessToken 获取 NameIdentifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29282993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com