Search code examples
apioutlook-restapi

Outlook's API hanging before granting request?


Is the Node.js tutorial for Outlook's Mail API out of date?

I cloned the repo, installed the versions the dependencies from there:

"@microsoft/microsoft-graph-client": "^0.4.0",
"es6-promise": "^4.1.0",
"simple-oauth2": "^1.0.1"

And registered the app, added a valid redirect URI and a replaced the Secret Key and Client ID, but for some reason, I'm getting an Access token error: Bad Request error. Error is coming from this endpoint:

http://localhost:8000/authorize?code=M05e30bdf-af17-916a-8707-b1a8eafdc6b2


Solution

  • First you should update those dependencies to:

    "@microsoft/microsoft-graph-client": "^1.0.0",
    "es6-promise": "^4.1.0",
    "simple-oauth2": "^1.4.0"
    

    There is an issue with the sample if you login with an Outlook.com address as it looks like you're doing. The problem is that there is no mail attribute on the Outlook.com user as returned by Graph.

    The quick fix is to replace the line of code in the getUserEmail function from:

    callback(null, res.mail);
    

    to:

    callback(null, res.mail ? res.mail : res.userPrincipalName);
    

    All that being said you probably should have logged this as an issue in the GitHub repository :)