【问题标题】:Unable to verify Azure AD token with NestJS application无法使用 NestJS 应用程序验证 Azure AD 令牌
【发布时间】:2023-01-12 19:42:13
【问题描述】:

我正在尝试验证蔚蓝广告与我的令牌嵌套后端应用程序。我正在使用登录到 Azure AD反应前端应用程序,现在,手动从响应中获取 access_token。然后我有这个守卫嵌套:

@Injectable()
export class AzureADStrategy extends PassportStrategy(
  BearerStrategy,
  'azure-ad',
) {
  constructor() {
    super({
      identityMetadata: `https://login.microsoftonline.com/${tenantID}/v2.0/.well-known/openid-configuration`,
      clientID,
      clientSecret,
      loggingLevel: 'debug',
      loggingNoPII: false
    });
  }

  async validate(response: any) {
    console.log(response);
  }
}

export const AzureGuard = AuthGuard('azure-ad');

当我将它应用于某个端点时,我试图获取此 URL,例如:

curl localhost:9000/test --header 'Authorization: Bearer xyz'

但是我无法进行身份验证,并且收到此错误日志:

{"name":"AzureAD: Bearer Strategy","hostname":"<hostname>","pid":1713974,"level":30,"msg":"authentication failed due to: invalid signature","time":"2022-11-03T13:00:51.213Z","v":0}

我应该如何配置它才能使其工作?

【问题讨论】:

  • 我假设您已经能够正常登录,然后将详细信息传递给 API。在验证时,这就是我所拥有的并且工作正常。

标签: node.js azure azure-active-directory nestjs passport.js


【解决方案1】:

我假设您已经能够正常登录,然后将详细信息传递给 API,并且您的用户已在 APP 下注册。

在验证时,这就是我所拥有的并且工作正常。

  async validate(data) {
    return data;
  }

这是我为了让它工作而遵循的示例 - https://medium.com/adidoescode/azure-ad-for-user-authentication-with-vue-and-nestjs-4dab3e96d240

【讨论】:

    猜你喜欢
    • 2022-11-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-17
    • 1970-01-01
    • 2019-02-20
    • 2021-08-10
    • 2016-12-05
    • 2018-02-03
    相关资源
    最近更新 更多