0
votes

I am writing Oauth using Exchange client. I have registered my app at apps.dev.microsoft.com. I am using JavaScript with Node.js. To perform the Oauth, I have used passport with several different strategies, but none of them seem to work for me. Some of them were missing profile information, and this last one I am using does not return me the access token. I have debugged the lib, but I don't know what I am doing wrong. Here is the lib I am using:

https://github.com/Azure-Samples/active-directory-node-webapp-openidconnect. I am using the OIDC strategy. So this returns a profile obj but access and refresh token is "undefined".It does return a authorization 'code' to make the token request. Redirect url, and all other meta data is fine such as: prompt: 'login', response_mode: 'query', state: true, authorizationURL: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', tokenURL: 'https://login.microsoftonline.com/common/oauth2/v2.0/token'

Also, client ID , client secret and callbackURL are correct.

Did I miss something essential in the process or MSFT oauth with passport is broken?

1
Why did this guy get a down vote for this? Looks like a good question to me. - Jeremy Foster

1 Answers

0
votes

As passport SDK doesn’t store accessToken and refreshToken in user profile. So we can modified sdk file to get tokens.

We can find these code in node_modules/passport-azure-ad/lib/passport-azure-ad/oidcstrategy.js begin in line 176 : log.info('TOKEN RECEIVED'); log.info('Access Token: ' + accessToken); log.info(''); log.info('Refresh Token: ' + refreshToken); log.info(''); log.info(params); log.info('----'); And we can find profile is defined in line 229 and 265. for easy use, we can directly add the tokens in the profile, for example, below code var profile = {}; we add profile.accessToken = accessToken;.