【问题标题】:ADAL Angular2 appid missing in JWT token (Unauthorized response)JWT 令牌中缺少 ADAL Angular2 appid(未经授权的响应)
【发布时间】:2017-10-03 08:37:01
【问题描述】:

我在 Agular2 项目中使用 ADAL 库针对 Azure AD 对用户进行身份验证,一旦用户通过身份验证调用 WebAPI 以使用 REST 调用获取一些信息。所有这些都适用于 AngularJS-AzureAD-WebAPI 场景。

按照MS文章创建示例项目https://blogs.msdn.microsoft.com/premier_developer/2017/04/26/using-adal-with-angular2

WebAPI 接收来自 Angular2 项目的调用,但请求具有匿名的授权令牌。经过进一步研究,发现 JWT 缺少 appid 值,并且 aud 属性包含 GUID,即应用程序 ID。

工作调用 JWT:(AngularJS 到 WebAPI)

appid:在 Azure 中注册的本机应用程序的 GUID
aud:someone.onmicrosoft.com/CortanaWebAPI

不工作调用 JWT:(Angular2 到 webAPI)

appid:此属性没有条目
aud:在 Azure 中注册的本机应用程序的 GUID

adal 配置

const endpoints = {
“https://localhost:44383/”: “http://someone.onmicrosoft.com/CortanaWebAPI”
};
public get getAdalConfig(): any {
return {
tenant: ‘someone.onmicrosoft.com’,
clientId: ‘9d9cd8dd-087a-4e87-b3f9-6e7ded2b5e82’,
redirectUri: window.location.origin + ‘/’,
postLogoutRedirectUri: window.location.origin + ‘/’,
endpoints: endpoints
};
}

不知道为什么会这样,感谢任何帮助。

【问题讨论】:

    标签: angular azure angular2-services adal


    【解决方案1】:

    问题与您正在开发的客户端类型无关。这取决于您正在开发的令牌(id_token 或 access_token)。

    AFAIK,没有appid 声明仅在 access_token 中发出。要解决此问题,您需要获取 access_token 而不是 id_tokenaud 声明取决于您发送令牌请求时的 resourcescope 参数。请在您的 Web API 项目中配置相应的aud

    【讨论】:

    • Web API 在 Azure 中注册为 APi 应用程序,Angular2 注册为本机应用程序。我想我被困在向 adal 服务注入 HTTP 服务,不知道如何在 Angular2 项目中做到这一点。或者它可能与“ProtectedResourceInterceptor”没有添加到 adal 服务有关。我正在使用这个示例代码github.com/vsaroopchand/angular2-seed
    • 是的,链接中的代码示例没有注入访问令牌。您可以参考调用 Azure AD Graph 的代码示例 here。如果您有任何问题,请随时告诉我。
    猜你喜欢
    • 2016-03-08
    • 1970-01-01
    • 2018-06-05
    • 2017-07-01
    • 1970-01-01
    • 2017-07-29
    • 2019-11-26
    • 2020-02-15
    • 2019-07-12
    相关资源
    最近更新 更多