问题
I have a WebAPI application which authenticates users with their Azure B2C token they have acquired from signing in with their credentials.
I need to write some tests against my WebAPI now but I'm not sure how I can automate acquiring a token given that I need to sign in on https://login.microsoftonline.com
...
Short of using selenium or something to sign in - is there another alternative for acquiring a token to use?
回答1:
I assume that you want to get token with non-interactive.
I think you can use resource owner password credentials flow in AAD B2C.
NOTE:In Azure Active Directory (Azure AD) B2C, the following options are supported:
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.
This flow can let you obtain token without UI.
Also, client credentials flow and OAuth 2.0 JWT bearer credential grant, also known as the on-behalf-of flow are not supported in AAD B2C currently. You can see the limitations in this documentation.
来源:https://stackoverflow.com/questions/51079730/automated-endpoint-testing-protected-by-azure-ad-b2c