[英]Need help in getting an access-token using Passport-azure-ad npm module and OIDCStrategy
I am trying to call Microsoft Graph API from my NodeJS express webapp and I am not able to fetch an access token from AAD.我正在尝试从我的 NodeJS express webapp 调用 Microsoft Graph API,但我无法从 AAD 获取访问令牌。
I am able to successfully login as well as able to get the user's profile,(able to get the code and id_token) and next I want to fetch the access token so that I call make the Graph Api call.我能够成功登录并能够获取用户的个人资料(能够获取代码和 id_token),接下来我想获取访问令牌,以便我调用 Graph Api 调用。
Can someone please help understand how can I fetch the access token from the OIDCStrategy?有人可以帮助了解如何从 OIDCStrategy 获取访问令牌吗?
I found the fix for the same.我找到了相同的解决方法。
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);
});
});
}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.