【发布时间】:2020-07-05 10:52:07
【问题描述】:
我正在尝试通过 Angular 9 前端 访问安全的 .net core 3.1 Web API。我使用了来自 MSAL Angular repo 的 Angular 9 代码示例。
我可以使用我自己的 Azure AD 应用注册成功登录,但在调用我的端点(用 [Authorize] 装饰)时,我在前端和邮递员(预期)中收到 401。
我的 Angular 拦截器甚至没有将请求中的不记名令牌添加到 API,因为 getScopesForEndpoint() 为请求返回 null:
let scopes = this.auth.getScopesForEndpoint(req.url);
console.log(scopes);
// scopes is null here.
如果我像这样将作用域硬编码到拦截器中:
scopes = [
"user.read",
"openid",
"profile",
"api://[My API ID]/weatherforecast"
];
我收到此错误:
InteractionRequiredAuthError: AADSTS65001: The user or administrator has not consented to use the
application with ID '[MY APP CLIENT ID]' named '[MY APP]'. Send an interactive
authorization request for this user and resource.
我在此处遵循本教程:Tutorial 并将我的 Azure AD 配置为与此非常相似。唯一的重大变化是我允许 MutiTenant 而不是 SingleTenant:
根据错误,我的 Angular 应用似乎没有向 API 注册,但我认为这就是 Azure AD 中的内容:
我是否错过了允许我的应用调用我的 API 的授权端点的步骤?这是一个帖子,与我遵循的设置非常相似 Related SO Post。唯一的区别是我的 Web API 在https://localhost:44381/weatherforecast 上,而不是部署到 Azure。接受的答案似乎对我的情况没有帮助。这里还有另一个非常相似的帖子:Related SO Post 2,但答案是关于 Cors 问题,这是不相关的。
【问题讨论】:
标签: azure asp.net-core-webapi msal msal.js