如何让MS Identity SPA的例子在组织和个人账户中发挥作用。

问题描述 投票:0回答:1

我正在关注 这个环节 来做我自己的项目。

我的项目有

  1. 架构

  2. Asp.Net Core Web Api

从Hotmail中访问用户的邮件.Reactjs应用和WebApi生活在不同的服务器上。

这个例子几乎是我所需要的,但它只接受同一组织内的账户,不接受个人账户。

我想我只需要在相关配置中把Tenant ID从特定ID改为 "common "就可以了。

AnyOrg + 个人账户enter image description here

enter image description here

这里是Angular的配置

{
  "auth": {
    "clientId": "28xxx12",
    "authority": "https://login.microsoftonline.com/common",
    "validateAuthority": true,
    "redirectUri": "http://localhost:4200",
    "postLogoutRedirectUri": "https://localhost:44321/signout-oidc",
    "navigateToLoginRequestUrl": true
  },
    "cache": {
        "cacheLocation": "localStorage"
    },
  "scopes": {
    "loginRequest": [ "openid", "profile", "Mail.Read", "offline_access", "user.read"]
  },
    "resources": {
      "todoListApi": {
        "resourceUri": "https://localhost:44351/api/todolist/",
        "resourceScope": "https://papayee008.onmicrosoft.com/papayee008/access_as_user"
      }
    }     
}

这里是Web Api的配置。

{
  "AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "Domain": "papayee008.onmicrosoft.com",
    "TenantId": "common",
    "ClientId": "28xxx12"
  },
  "https_port": 44351,
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

但当我试图用我的个人账户登录时,它给我抛出了这个错误。enter image description here

asp.net-core microsoft-graph msal microsoft-identity-platform
1个回答
1
投票

最简单的解决方案是为SPA和API使用相同的appclient id。也就是说,与其为每个组件进行单独的应用注册(如readme中建议的那样),不如简单地进行一个应用注册,在那里你可以将以下步骤结合起来,即 注册服务应用程序(TodoListAPI)。注册客户端应用程序(TodoListSPA)。 的readme中。

编辑:从最后一张截图来看,也可能是你在AAD门户上对 "支持的账户类型 "的修改还没有生效。通常会有几秒钟的延迟,如果你在这段时间内尝试用个人账户登录,截图中的问题也是意料之中的。

© www.soinside.com 2019 - 2024. All rights reserved.