okta / samples-nodejs-express-4

Express 4 samples. Will publish an artifact that can be consumed by end-to-end sample repos
Other
120 stars 118 forks source link

Cannot run the resource server #58

Closed adriatic closed 5 years ago

adriatic commented 5 years ago

This issue describes the failure of the Express Resource Server Example, where the command npm run resource-server results with

> @okta/samples-nodejs-express-4@3.0.0 resource-server C:\work\learning\okta\samples-nodejs-express-4
> node resource-server/server.js

C:\work\learning\okta\samples-nodejs-express-4\node_modules\@okta\configuration-validation\dist\lib.js:66
    throw new ConfigurationValidationError('Your client ID is missing. ' + copyCredentialsMessage);
    ^

Error: Your client ID is missing. You can copy it from the Okta Developer Console in the details for the Application you created. Follow these instructions to find it: https://bit.ly/finding-okta-app-credentials
    at new ConfigurationValidationError (C:\work\learning\okta\samples-nodejs-express-4\node_modules\@okta\configuration-validation\dist\lib.js:27:141)
    at configUtil.assertClientId (C:\work\learning\okta\samples-nodejs-express-4\node_modules\@okta\configuration-validation\dist\lib.js:66:11)
    at new OktaJwtVerifier (C:\work\learning\okta\samples-nodejs-express-4\node_modules\@okta\jwt-verifier\lib.js:25:5)
    at Object.<anonymous> (C:\work\learning\okta\samples-nodejs-express-4\resource-server\server.js:19:25)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @okta/samples-nodejs-express-4@3.0.0 resource-server: `node resource-server/server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @okta/samples-nodejs-express-4@3.0.0 resource-server script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

The gist of this failure is described as Error: Your client ID is missing.

I believe that the data in the file .samples.config.json are correct - in particular, the client ID is set to 0oah36nrrdAZ7r4a00h7 - as defined at https://dev-621259-admin.oktapreview.com/admin/app/oidc_client/instance/0oah36nrrdAZ7r4a00h7/#tab-general - and the only possible problem that I can see is the use of the key "cid" to refer to client ID in the "assertClaims"section (shown below):

   "assertClaims": {
      "aud": "api://default",
      "cid": "0oah36nrrdAZ7r4a00h7"
    }

Am I missing something obvious?

webshift1 commented 5 years ago

If you haven't fixed this by now, the issue is in the OktaJwtVerifier function: const oktaJwtVerifier = new OktaJwtVerifier({ issuer: sampleConfig.resourceServer.oidc.issuer, assertClaims: sampleConfig.resourceServer.assertClaims });

should actually include the clientId key, like so: const oktaJwtVerifier = new OktaJwtVerifier({ issuer: sampleConfig.resourceServer.oidc.issuer, clientId: {clientid}, assertClaims: sampleConfig.resourceServer.assertClaims }); Hope this helps some.

adriatic commented 5 years ago

Hi @SPNexus - frankly, I gave up on this, correctly concluding that Okta does not care about having their sample code tested and verified. Three months of silence is enough to make such conclusion 😄

swiftone commented 5 years ago

Closing this as the sample has been updated to reflect the correct requirements.