首页 文章

使用承载身份验证与Azure Active Directory访问令牌

提问于
浏览
0

我使用Passport AAD project和承载策略来保护我的 endpoints . 在我登录时收到带有OIDC策略的令牌后,我似乎无法获得承载策略来验证访问令牌的签名 . 我明白了:

authentication failed due to: invalid signature

验证id_token没有问题,但如果无法使用AAD刷新id_token,我宁愿不将它用于我们的客户端应用程序 . 此外,当使用jwt.io来测试published public keys的验证时,我看到了同样的问题(可以验证id_token,但不能验证access_token) .

我在抓取访问令牌时错过了一个步骤,或者我对如何验证访问令牌有所了解?

Update with more details

我正在向我的租户请求访问令牌:

identityMetadata: https://login.microsoftonline.com/your_tenant_name.onmicrosoft.com/.well-known/openid-configuration,
responseType: 'id_token code'

在AAD Passport项目中使用OIDCStrategy .

const callbackOIDC = (iss, sub, profile, accessToken, refreshToken, params, done) => {
  return done(null,{
    profile,
    accessToken,
    refreshToken
  });
};

passport.use(new OIDCStrategy(config.creds, callbackOIDC));

然后我运行authenticate,如下所示:

auth.adCallback = function (req, res, next) {
  passport.authenticate('azuread-openidconnect', {
    response: res,
    resourceURL: 'https://graph.microsoft.com',
    session: false
  }, function (err, user, info) {
    console.log(user.access_token);
  })(req, res, next);
};

我想我可能一直在通过指定资源URL来请求上面的图形访问令牌 . 如果我删除该资源URL,我仍然会获得访问令牌,但是承载策略会抛出无效的令牌错误(而不是无效的签名错误) . 是否有不同的资源URL我应该设置为与我的租户匹配并获取我正在寻找的访问令牌?

1 回答

  • 1

    你要求什么访问令牌?例如,如果要对Microsoft Graph使用访问令牌,则图表的任务是验证它们 - 而不是您的应用程序 . 您是否可以扩展您尝试实施的确切方案,以及您需要刷新id_tokens的时间点?

相关问题