【问题标题】:Azure AD Msal Interceptor Access TokenAzure AD Msal 拦截器访问令牌
【发布时间】:2021-12-28 02:08:39
【问题描述】:

我正在使用 azure MSAL 来验证我的 API,但问题是我正在使用 DevExtreme 自定义存储进行服务器端分页。

Msal Interceptor 工作并为 HttpClient 自动生成令牌,但在这种情况下,我不通过 h​​ttp 发送请求。

如果我使用登录后获得的访问令牌,则会发生错误无效签名,如果使用 IdToken,则 401 我该如何解决此问题。

MSALInterceptorConfigFactory:

protectedResourceMap.set('https://localhost:44379/api/approveMilestones', ['api://cb343c76-cd5b-4af6-8229-014b2522adab/access_as_user']);

我获取 accessToken 和 IdToken 的登录响应

this.authService.loginPopup()
  .subscribe((response: AuthenticationResult) => {
    AuthenticationHelper.setToken(response.accessToken);
    this.router.navigate(['/payments-approval']);
  });

I'm getting accessToken and IdTOken both in result but these are not working if i send them with request for Bearer

【问题讨论】:

  • 如果您检查jwt.ms 的访问令牌,“aud”(受众)值是多少?
  • aud 值与我的 clientID 相同
  • 好吧,这听起来是对的。您的后端身份验证是如何配置的?
  • 后端身份验证很好,我对其进行了测试,但问题是我没有处理某些 API 的 http 请求。
  • 有什么方法可以让我们从浏览器获取不记名令牌?

标签: angular api .net-core azure-active-directory msal-angular


【解决方案1】:

在向服务器发送请求时,跨域时范围为空。您可以从小角度创建自己的拦截器,然后您可以在开发模式下注入代码。

先将token存入localStorage:

localStorage.setItem ('token', result.token);

向服务器发送请求时,从浏览器获取令牌

const token = localStorage.getItem (‘token'); 并使用这样的请求发送令牌。

阅读更多here

【讨论】:

    猜你喜欢
    • 2021-10-08
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 2020-12-21
    • 2017-04-26
    • 2020-07-05
    • 1970-01-01
    • 2020-10-17
    相关资源
    最近更新 更多