我有一个 WebAPI 应用程序,它使用用户通过使用凭据登录获得的 Azure B2C token 进行身份验证。
我现在需要针对我的 WebAPI 编写一些测试,但我不确定如何自动获取 token ,因为我需要登录 https://login.microsoftonline.com
...
缺少使用 selenium 或其他东西来登录 - 是否有另一种选择来获取要使用的 token ?
最佳答案
我假设您想以非交互式方式获取 token 。
我想你可以用 resource owner password credentials flow in AAD B2C .
注意:在 Azure Active Directory (Azure AD) B2C 中,支持以下选项:
Native Client: User interaction during authentication happens when code runs on a user-side device. The device can be a mobile application that's running in a native operating system, such as Android, or running in a browser, such as JavaScript.
Public client flow: Only user credentials, gathered by an application, are sent in the API call. The credentials of the application are not sent.
Add new claims: The ID token contents can be changed to add new claims.
此流程可以让您无需 UI 即可获取 token 。
此外,AAD B2C 目前不支持客户端凭据流和 OAuth 2.0 JWT 不记名凭据授予,也称为代表流。您可以看到限制 in this documentation .
关于asp.net-web-api - 受 Azure AD B2C 保护的自动化端点测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51079730/