nodejs-connect-rest-sample icon indicating copy to clipboard operation
nodejs-connect-rest-sample copied to clipboard

Mismatched Redirect URL using the MS Graph quick-start page

Open BurtHarris opened this issue 9 years ago • 10 comments

A sample app generated using the Microsoft Graph quick-start page fails to operate correctly due to a mismatch between the Redirect URL configured for the application. The quick start sets this parameter to http://localhost:3000/login, while the sample code seems to expect it set to http://localhost:300/token

Without modification, the user ends up with an error message page that says:

We're unable to complete your request

Microsoft account is experiencing technical problems. Please try again later.

Unfortunately, this is a misleading and non-actionable error message. The URL for this page actually includes a query string that seems designed to allow for a better error message to be displayed, but this is unfortunately not used.

Sample: Error message URL: https://login.live.com/err.srf?lc=1033#error=invalid_request&error_description=The+provided+value+for+the+input+parameter+'redirect_uri'+is+not+valid.+The+expected+value+is+'https://login.live.com/oauth20_desktop.srf'+or+a+URL+which+matches+the+redirect+URI+registered+for+this+client+application.&state=a9SlXZGisoIQrPQUbDHX732izad7LJzM

BurtHarris avatar May 11 '17 18:05 BurtHarris

Thanks for catching this as well. This appears to be an issue with the quick start, since the sample in the repo already sets the redirect URL to http://localhost:3000/token. We'll get the quick start fixed ASAP.

jamescro avatar May 11 '17 19:05 jamescro

I see the quick-start generates configurations that work across samples in several languages. Is the use of "token" vs. "login" generally correct, or should this be considered a bug in the nodejs sample?

BurtHarris avatar May 11 '17 19:05 BurtHarris

Note also that the login.live.com page really doesn't implement good error message practices, the default message leaves the impression the problem is something Microsoft will have to address. This failure to propagate a good error description contributes to the general impression that the new authentications mechanisms are HARD, when it really shouldn't be..

BurtHarris avatar May 11 '17 19:05 BurtHarris

This is a bug in the quick start and the readme, since updates to the code changed the redirect URI that you need to register. I've verified that the sample works if you register a client with http://localhost:3000/token as the redirect URI. The readme and the quick start need to be updated to reflect that. I will update the readme and pursue a fix with the quick start.

As for the poor error messaging, you make an excellent point. Unfortunately it is not something that we can control (other than to pass along feedback) and it's not a problem specific to this repo.

jamescro avatar May 11 '17 19:05 jamescro

I should also point out that the problem with the undefined fields in your other issue appears to be a side-effect of this registration issue. Changing the redirect URI in the config.js file to the one that is registered for the sample will get you past the authentication stage, but you end up redirecting to the wrong page after successful authentication.

jamescro avatar May 11 '17 19:05 jamescro

This is now fixed in the live quick start.

jamescro avatar Jun 01 '17 21:06 jamescro

I just ran through the node.js quick start again from scratch, starting from using the Microsoft Graph quick-start page .

I still get an error, though perhaps later in the flow of things than before.

Listening on port 3000
GET / 200 83.105 ms - 1463
GET /stylesheets/style.css 200 4.000 ms - 647
GET /login 302 383.163 ms - 0
GET /token?code=<is this a secret> 200 1072.329 ms - 2015
GET /stylesheets/style.css 304 10.239 ms - -
C:\try\TryAgain\routes\index.js:139
  res.render('error', {
     ^

TypeError: Cannot read property 'render' of undefined
    at renderError (C:\try\TryAgain\routes\index.js:139:6)
    at graphHelper.getProfilePhoto (C:\try\TryAgain\routes\index.js:73:19)
    at request.get.set.end (C:\try\TryAgain\utils\graphHelper.js:35:6)
    at Request.callback (C:\try\TryAgain\node_modules\superagent\lib\node\index.js:688:3)
    at C:\try\TryAgain\node_modules\superagent\lib\node\index.js:883:18
    at IncomingMessage.<anonymous> (C:\try\TryAgain\node_modules\superagent\lib\node\parsers\json.js:16:7)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)

BurtHarris avatar Jun 02 '17 02:06 BurtHarris

I'm really happy with TypeScript strict null checking. It's not a quick fix, but it can really help head-off problems at build time.

BurtHarris avatar Jun 02 '17 02:06 BurtHarris

I ran through the quick start successfully. Could you look in your config.js file and verify that correct values were entered for client id and secrey? This is different from the original issue.

jamescro avatar Jun 02 '17 03:06 jamescro

Your right, it separate issues. Opened issue #63

BurtHarris avatar Jun 02 '17 18:06 BurtHarris