node.js - 使用 Passport 和 Passport-azure-ad 时没有刷新 token

标签 node.js azure oauth office365 passport.js

我正在尝试使用 Passport 连接到 Office365。我收到身份验证提示并返回访问 token 。问题是刷新 token 未定义。

我的设置

// In app.js
const creds = {
    redirectUrl: 'http://localhost:3000/token',
    clientID: '<myClientId>',
    clientSecret: '<mySecret>',
    identityMetadata: 'https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration',
    allowHttpForRedirectUrl: true, // For development only
    accessType: 'offline',
    responseType: 'code',
    validateIssuer: false, // For development only
    responseMode: 'query',
    scope: [
        'Contacts.Read',
        ...
    ]
};

const callback = (iss, sub, profile, accessToken, refreshToken, done) => {
  console.log('Refresh Token: ', refreshToken); // this is undefined
  done(null, {
    profile,
    accessToken,
    refreshToken
  });
};

passport.use(new OIDCStrategy(creds, callback));

// When I authenticate
const passportSettings = {
  accessType: 'offline',
  approvalPrompt: 'consent'
};

// Authentication request.
router.get('/login', (req, res, next) => {
  passport.authenticate('azuread-openidconnect', passportSettings, (err, user, info) => {
        // Do stuff.
  });
});

我尝试过的事情:

  • 取消对我注册的用户的应用的授权。
  • 移动 accessType 设置的位置。

我真的不知道为什么这不起作用。根据 Google 策略,仅设置“离线”类型似乎就足够了。

最佳答案

看来您需要将 offline_access 范围添加到应用注册和配置中。请参阅https://github.com/AzureAD/passport-azure-ad/issues/322 .

关于node.js - 使用 Passport 和 Passport-azure-ad 时没有刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44591830/

相关文章:

node.js - NodeJS : for loop and promises

Azure Pipeline 从 Azure 存储库 check out 代码并构建工件

java - 使用 oAuth - fatsecret API 向 REST API 发送请求

api - 使用 oauth 测试 REST API 的 Http 客户端应用程序

node.js - NodeJS,如何强制异步 for 循环在传递到下一次迭代之前等待 HTTP 请求解析,这样我们就不会收到 EMFILE 错误?

node.js - 函数返回对象作为promise {pending}

javascript - 如何在处理输出时暂停和取消暂停 Node 对象流

twitter - 您将如何使用 Azure 表存储来处理类似 Twitter 的应用程序?

silverlight - 通过 Silverlight 访问 Windows Azure API?

javascript - chrome.identity.getAuthToken 和刷新 token ?