【问题标题】:Need help in getting an access-token using Passport-azure-ad npm module and OIDCStrategy在使用 Passport-azure-ad npm 模块和 OIDCStrategy 获取访问令牌方面需要帮助
【发布时间】:2021-07-28 04:14:57
【问题描述】:

我正在尝试从我的 NodeJS express webapp 调用 Microsoft Graph API,但我无法从 AAD 获取访问令牌。

我能够成功登录并且能够获取用户的个人资料(能够获取代码和 id_token),接下来我想获取访问令牌,以便我调用 Graph Api 调用。

有人可以帮助了解我如何从 OIDCStrategy 获取访问令牌吗?

【问题讨论】:

    标签: node.js passport.js access-token passport-azure-ad


    【解决方案1】:

    我找到了相同的解决方法。

    passport.use(new OIDCStrategy({
            identityMetadata: configAuth.creds.identityMetadata,
            clientID: configAuth.creds.clientID, 
            responseType: configAuth.creds.responseType,
            responseMode: configAuth.creds.responseMode,
            redirectUrl: configAuth.creds.redirectUrl, 
            allowHttpForRedirectUrl: configAuth.creds.allowHttpForRedirectUrl,
            clientSecret: configAuth.creds.clientSecret,
            validateIssuer: configAuth.creds.validateIssuer,
            isB2C: configAuth.creds.isB2C,
            issuer: configAuth.creds.issuer,
            passReqToCallback: configAuth.creds.passReqToCallback, 
            scope: configAuth.creds.scope,
            loggingLevel: configAuth.creds.loggingLevel, 
            nonceLifetime: configAuth.creds.nonceLifetime,
            nonceMaxAmount: configAuth.creds.nonceMaxAmount,
            useCookieInsteadOfSession: configAuth.creds.useCookieInsteadOfSession,
            cookieEncryptionKeys: configAuth.creds.cookieEncryptionKeys,
            clockSkew: configAuth.creds.clockSkew,
        }, (req, iss, sub, profile, access_token, refresh_token, params, done) => {
            console.log(`Profile >>>> ${JSON.stringify(profile)}`);
            if(!profile.oid) {
                return done(new Error("No oid found"), null);
            }
            profile.tokens = params;
            // console.log(`Access-Token >>>> ${access_token}`);
            // console.log(`Refresh-Token >>>> ${refresh_token}`);       
            // console.log(`Profile >>>>>>>>>>>>>> ${JSON.stringify(profile)}`);
            process.nextTick(() => {
                findByOid(profile.oid, (err, user) => {
                    if(err) {
                        return done(err);
                    }
                    if(!user) {
                        users.push(profile);
                        return done(null, profile);
                    }
                    return done(null, user);      
                });
            });
        }));
    

    【讨论】:

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