【问题标题】:Azure ad authentication SPA token not able to authenticate by my APIAzure 广告身份验证 SPA 令牌无法通过我的 API 进行身份验证
【发布时间】:2021-03-23 15:52:50
【问题描述】:

我在同一天有 API 和 SPA。我已经设置了 Expose an API 并授予了我的 SPA 权限。 但是当我登录我的 SPA 时,我传递给我的 API 的返回令牌未被授权。

我还需要在我的 SPA 中做些什么?

我使用 React js 和 MSAL 登录。

【问题讨论】:

    标签: reactjs azure azure-active-directory


    【解决方案1】:

    您可能会错过范围。范围格式为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'"]
    }
    

    https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#use-the-access-token-to-access-the-secured-resource

    【讨论】:

    • 关于范围格式:api://ClientId/Local_API_Access。我关注了你分享的链接,但仍然是同样的问题。
    • @StillANoob 你能分享一下你的错误的细节吗?只有 403?
    • 只是 401,未捕获(承诺中)错误:请求失败,状态码 401
    • 我已成功登录,但从 MSAL 返回的令牌无权访问我的 API。
    • 您在哪一步遇到错误,点击接受
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-17
    • 2020-07-17
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    相关资源
    最近更新 更多