我已在 Azure Active Directory 中注册 xyz.com
域。然后我在 Azure AD 应用程序注册中注册了一个 React 单页应用程序。
我在 React 应用程序中使用 domain_name/AllowAnonymous
( http://example.com/user_impersonation ) 范围来使用 msal-react 生成 token 。
从 React 应用程序生成的 token 包含 domain_name/AllowAnonymous
( http://example.com/user_impersonation ) 作为 JWT token 声明中的受众。
在后端,我使用 client-id (api://
但是 token 有 domain_name/AllowAnonymous
( http://example.com/user_impersonation ) 作为受众,因此 token 验证失败。
如何在后端 C# 代码中通过 client-id 获取 domain_name
以通过 domain_name
验证 token ?
在前端应用程序中将 client_id 设置为范围以生成 JWT token 是否安全?
最佳答案
我认为您可以根据此配置应用程序:https://learn.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-react
Client_Id是公共(public)信息,您可以放心地将其添加到网络应用程序中。
另请记住,Azure Active Directory 中有 3 种类型的 token : https://learn.microsoft.com/en-gb/azure/active-directory/develop/security-tokens
如果您需要验证 token ,请查看示例:https://learn.microsoft.com/en-us/azure/active-directory/develop/sample-v2-code
关于azure - Adal 到 Msal 转换 -> JWT token 验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72858474/