Oauth 2.0 在Postman中复制ADAL.JS-authenticated请求
我有一个.NETWebAPI和一个使用的小型vanilla JS应用程序,我已经设法让它们彼此友好地交谈并正确地进行身份验证 如果我Oauth 2.0 在Postman中复制ADAL.JS-authenticated请求,oauth-2.0,azure-active-directory,postman,adal,adal.js,Oauth 2.0,Azure Active Directory,Postman,Adal,Adal.js,我有一个.NETWebAPI和一个使用的小型vanilla JS应用程序,我已经设法让它们彼此友好地交谈并正确地进行身份验证 如果我console.log从adalAuthContext.acquireToken()返回的令牌,并在Postman中手动将其作为Authorization:Bearer{{{token}}输入,我还可以从后端获得有效的、经过身份验证的响应 但是,我不知道如何配置Postman内置的OAuth2.0身份验证UI来自动获取令牌。我已经设法以几种方式获得令牌,但后端都不接
console.log
从adalAuthContext.acquireToken()
返回的令牌,并在Postman中手动将其作为Authorization:Bearer{{{token}}
输入,我还可以从后端获得有效的、经过身份验证的响应
但是,我不知道如何配置Postman内置的OAuth2.0身份验证UI来自动获取令牌。我已经设法以几种方式获得令牌,但后端都不接受
如何配置邮递员以与库相同的方式获取令牌?
为了完整起见,这里有一些代码: 后端配置:
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
TokenValidationParameters = new TokenValidationParameters { ValidAudience = "<app-id>" },
Tenant = "<tenant>",
AuthenticationType = "WebAPI"
});
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
app.UseWebApi(config);
}
const backendUrl = 'http://localhost:55476';
const backendAppId = '<app-id>';
const authContext = new AuthenticationContext({
clientId: backendAppId,
tenant: '<tenant>',
endpoints: [{ [backendAppId]: backendAppId }],
cacheLocation: 'localStorage'
});
因此,由于Azure AD v1端点不完全符合标准,因此我们不得不以一种稍微奇怪的方式进行操作 邮递员:
https://login.microsoftonline.com/yourtenant.onmicrosoft.com/oauth2/authorize?resource=https%3A%2F%2Fgraph.microsoft.com
yourtanent.onmicrosoft.com
。
或者,如果你的应用程序是多租户的,你也可以使用common
。
资源
是最重要的参数(不符合标准)。
它告诉AAD您想要访问令牌的API。
在本例中,我为MS Graph API请求了一个令牌,它的资源URI为https://graph.microsoft.com
。
对于您自己的API,您可以使用它们的客户端id或应用程序id URI
以下是我的设置的屏幕截图:
authContext.acquireToken(backendAppId, (error, token) => {
// error handling etc omitted
fetch(backendUrl, { headers: { Authorization: `Bearer ${token}` } })
.then(response => response.json())
.then(console.log)
})