【发布时间】:2020-06-08 14:30:48
【问题描述】:
我正在尝试了解如何调用图形 API 以使用 msal-angular ("@azure/msal-angular": "^0.1.4") 拉回一些用户信息。 我还没有找到一个可行的例子/教程。
我已经设置了 Azure AD B2C。使用用户名作为登录密钥创建了一个本地帐户提供程序。 我创建了注册/登录流程并注册了一个 webapp 'b2c-app01'。对于 API 权限,我为应用授予了“user.read”权限。
我已使用以下 msal 配置登录
MsalModule.forRoot({
clientID: "00000000-0000-0000-0000-000000000000", // b2c-app01 in app registration
authority: "https://b2c-app01.b2clogin.com/tfp/b2c-app01.onmicrosoft.com/B2C_1_SignInOrSignUp",
validateAuthority: false,
接下来,我将尝试按照此示例 https://docs.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-javascript-spa 访问图形 API。
但是,我无法通过 acquireTokenSilent 调用。我将 ['user.read'] 传递给范围,并得到以下错误
this._user = this.authService.getUser();
let tokenResponse = await this.authService.acquireTokenSilent(
['user.read'],
);
console.log(tokenResponse);
The scope 'user.read' provided in the request is not supported.
我尝试将用户中返回的身份提供者 url 用于权限属性,但随后出现 CORS 错误。我什至不知道这是否有效,所以我没有进一步研究 CORS 错误
this._user = this.authService.getUser();
let tokenResponse = await this.authService.acquireTokenSilent(
['user.read'],
this._user.identityProvider,
this._user,
);
console.log(tokenResponse);
blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.。
关于我做错了什么或我缺少什么的任何建议?
编辑:
【问题讨论】:
标签: angular azure-ad-b2c msal.js