Angular 应用程序和 Spring 启动与 Azure AD 的集成

Integration of Angular Application and Spring Boot with Azure AD

我正在使用 angular 和 spring 引导构建应用程序。我需要从前端使用 Azure AD 进行 SSO,然后使用令牌保护 spring 引导服务。 (简而言之,我的 angular 将连接到 office 365 进行登录,然后用户将使用 spring 安全性对连接进行身份验证,它将验证令牌,如果有效,它将给出响应。) 在 angular 中,我使用 adal-angular4,在 spring 中使用 boot azure-active-directory-spring-boot-starter。 另外,如何在 Azure AD 门户中注册应用程序(前端和后端)。

我尝试使用一些文章。当我使用令牌点击 URL 时,我收到了邮递员的回复。

{
    "code": 500,
    "status": "failure",
    "path": "/api/echo",
    "message": "com.microsoft.aad.adal4j.AuthenticationException: {\"error_description\":\"AADSTS500131: Assertion audience does not match the Client app presenting the assertion. The audience in the assertion was '48eb1c7f-e02b-43a9-913a-XXXXXXXX' and the expected audience is 'a3edefea-1ff3-43ed-b2d7-=XXXXXXXXXXXXX' or one of the Application Uris of this application with App ID 'a3edefea-1ff3-43ed-b2d7-=XXXXXXXXXX'(PulseBE).\r\nTrace ID: 2aced69c-f12d-4b5d-97db-XXXXXXXXXX\r\nCorrelation ID: 226816c8-a2ed-488c-86ec-XXXXXXXXXXXXXXXX\r\nTimestamp: 2019-06-17 19:10:34Z\",\"error\":\"invalid_grant\",\"error_uri\":\"https:\/\/login.microsoftonline.com\/error?code=500131\"}",
    "timeStamp": "Tue Jun 18 00:40:35 IST 2019",
    "trace": null
}

iamelix,我遇到了同样的问题。我的问题是我的 auth URL 和 token URL 没有包含资源参数。

Azure 身份验证 URL 和令牌 URL 的格式如下。

Postman Azure AD

授权 URL 格式: https://login.microsoftonline.com/[tenant_id]/oauth2/authorize?resource=[application_id]

访问令牌URL格式https://login.microsoftonline.com/[tenant_id]/oauth2/token?resource=[application_id]

我的关键是将 resource 参数添加到身份验证 URL 和令牌 URL,现在我请求的令牌包括有效的观众所以它被 Azure AD 毫无错误地接受。我从这篇非常有用的文章中找到了以上信息:https://www.bruttin.com/2017/11/21/azure-api-postman.html