【发布时间】:2021-03-23 15:52:50
【问题描述】:
我在同一天有 API 和 SPA。我已经设置了 Expose an API 并授予了我的 SPA 权限。 但是当我登录我的 SPA 时,我传递给我的 API 的返回令牌未被授权。
我还需要在我的 SPA 中做些什么?
我使用 React js 和 MSAL 登录。
【问题讨论】:
标签: reactjs azure azure-active-directory
我在同一天有 API 和 SPA。我已经设置了 Expose an API 并授予了我的 SPA 权限。 但是当我登录我的 SPA 时,我传递给我的 API 的返回令牌未被授权。
我还需要在我的 SPA 中做些什么?
我使用 React js 和 MSAL 登录。
【问题讨论】:
标签: reactjs azure azure-active-directory
您可能会错过范围。范围格式为api://{client_id}/.default。
有一个使用代理流的示例:https://github.com/Azure-Samples/ms-identity-javascript-react-spa-dotnetcore-webapi-obo
在 ProfileSPA/src/utils/authConfig.js:
export const apiConfig = { resourceUri: "https://localhost:44351/api/profile", resourceScopes: ["Enter the API scopes as declared in the app registration 'Expose an Api' blade in the form of 'api://{client_id}/.default'"] }
【讨论】: