我正在尝试创建一个 webtest,它将使用令牌验证网站并加载网页。
但由于网站使用活动目录,它在通过浏览器访问时使用UseOpenIdConnectAuthentication和UseCookieAuthentication进行身份验证。
根据您的描述,我假设您可以利用包 Microsoft.Owin.Security.OpenIdConnect 和 Microsoft.Owin.Security.Cookies 通过 OpenId Connect 和 Azure AD 保护您的应用程序。
假设您的网站由 Azure Web 应用托管,我假设您可以利用 Authentication and authorization in Azure App Service 并配置 Authenticate with Azure AD,而不是在代码中手动使用中间件。但是您可以在代码中检查当前环境并使用中间件进行本地身份验证。
为了从 azure web 应用程序中获取经过身份验证的令牌,您可以通过浏览器访问以下 url 进行日志记录:
https://{your-app-name}.azurewebsites.net/.auth/login/aad
登录后,您将被重定向到如下网址:
https://{your-app-name}.azurewebsites.net/.auth/login/done#token={token}
您可以URL Decode 上面的token,检索authenticationToken 作为经过身份验证的令牌来访问您的Azure Web 应用程序,如下所示:
https://{your-app-name}.azurewebsites.net/xxx/xxx
Header: x-zumo-auth:{authenticationToken}
注意:authenticationToken 将在一小时后过期。
此外,对于 Azure Active Directory,您还可以利用 id_token 或 access_token 直接包含在 Authorization 标头中作为不记名令牌,如下所示:
https://{your-app-name}.azurewebsites.net/xxx/xxx
Header: Authorization:Bearer {id_token or access_token}
注意:为了在登录后检索id_token或access_token,您可以通过浏览器访问以下网址:
https://{your-app-name}.azurewebsites.net/.auth/me