【问题标题】:Resource identifier not provided for Angular SPA using Azure AD未为使用 Azure AD 的 Angular SPA 提供资源标识符
【发布时间】:2020-03-02 22:01:15
【问题描述】:

我正在使用 https://github.com/damienbod/dotnet-template-angular 中修改后的 Visual Studio 模板来构建一个使用 Asp.Net API 和 Azure AD 登录的 Angular SPA。这在 Angular 端使用 https://github.com/damienbod/angular-auth-oidc-client 与 Azure 对话。

我按预期获得了 Micosoft 登录,但在输入我的用户登录详细信息后,它返回错误:

AADSTS500013 - 未提供资源标识符

我在这里的一些其他问题中看到了这个错误,但是不同的应用程序设置没有使用相同的 Angular OIDC 客户端。我不确定这是问题所在还是我在 Azure 应用注册中遗漏了什么?

更新 我的 Azure 应用是使用旧版应用注册进行注册的,所以看起来像这样:

"oidc": {
    "issuer": "https://login.microsoftonline.com/[....]/",
    "client_id": "[...]",
    "scope": "openid",
    "resource": "https://graph.microsoft.com/"
}

【问题讨论】:

  • 我以为这个论坛是为了互相帮助,而不是让人们失望?

标签: angular azure openid-connect


【解决方案1】:

您是否在用于对用户进行身份验证的 Azure AD 中注册了您的应用程序?在那里,您将看到必须在 appsettings.json 文件中的 clientId 节点下为 ASP.NET 应用程序提供的应用程序 ID:

  "oidc": {
    "issuer": "https://login.microsoftonline.com/common/v2.0/",
    "client_id": "d4d8dc5a-3e3b-4cf8-9ba5-eee9e27764a1",
    "scope": "openid profile email",
    "resource": "https://graph.windows.net",
    "prompt": "consent"
  }

此外,请确保在 Angular 应用程序中包含 Azure AD 租户的 OIDC 配置,如 dotnet-angular-azure-ad-oidc 库的 loadConfig 函数的 cmets app.module.ts 中所述。

export function loadConfig(oidcConfigService: OidcConfigService) {
  console.log('APP_INITIALIZER STARTING');
  // https://login.microsoftonline.com/damienbod.onmicrosoft.com/.well-known/openid-configuration
  // jwt keys: https://login.microsoftonline.com/common/discovery/keys
  // Azure AD does not support CORS, so you need to download the OIDC configuration, and use these from the application.
  // The jwt keys needs to be configured in the well-known-openid-configuration.json
  return () => oidcConfigService.load(`${window.location.origin}/api/config/configuration`);
  //return () => oidcConfigService.load_using_custom_stsServer('https://localhost:44347/well-known-openid-configuration.json');
}

此配置可通过https://login.microsoftonline.com/{your-tenant-name}.onmicrosoft.com/.well-known/openid-configuration 访问。

【讨论】:

  • 不确定如何处理您提到的第二部分?我的 loadConfig 与您在原始 git repo 中显示的完全一样。我该如何配置? .Net Core API 控制器 ../api/config/configuration 不是从 Azure 获取必要的配置吗?
猜你喜欢
  • 2019-08-04
  • 1970-01-01
  • 2022-08-05
  • 1970-01-01
  • 1970-01-01
  • 2019-11-11
  • 2021-10-03
  • 1970-01-01
  • 2020-07-26
相关资源
最近更新 更多