panva / openid-client

OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
MIT License
1.83k stars 392 forks source link

openid-client 3.12.0+: regression in esm compatibility #238

Closed candu closed 4 years ago

candu commented 4 years ago

Describe the bug When loading latest openid-client in a node process with esm, Issuer discovery fails with a SyntaxError.

This was observed in openid-client v3.12.0, v3.13.0, v3.14.0; v3.11.0 appears to be unaffected.

To Reproduce Issuer and Client configuration: (inline or gist) - Don't forget to redact your secrets.

// Issuer configuration (issuer.metadata) and how it is constructed (discovery or manual?)
const issuer = await Issuer.discover(issuerUrl);

// Client configuration (client.metadata) and how it is constructed (fromUri or manual?)
{
  client_id: clientId,
  // either:
  token_endpoint_auth_method: 'none',
  // or:
  client_secret: clientSecret,
  redirect_uris: [ appRedirectUri ],
}

Steps to reproduce the behaviour:

  1. npm install --save openid-client@latest (or any version 3.12.0+);
  2. npm install esm;
  3. node -r esm;
  4. at the CLI prompt:
import { Issuer } from 'openid-client';
const url = /* YOUR OpenID URL HERE */;
Issuer.discover(url).then((issuer) => { console.log(issuer); });

Expected behaviour Issuer discovery works normally, and the issuer instance is logged successfully.

Environment:

Additional context

Stacktrace from node REPL:

(node:16588) UnhandledPromiseRejectionWarning: AggregateError: 
    SyntaxError: Unexpected token '=>'
        at Function.request (/home/vagrant/git/bdit_flashcrow/node_modules/openid-client/lib/helpers/request.js:27:3)
        at /home/vagrant/git/bdit_flashcrow/node_modules/openid-client/lib/issuer.js:242:38
        at Array.map (<anonymous>)
        at Function.discover (/home/vagrant/git/bdit_flashcrow/node_modules/openid-client/lib/issuer.js:240:22)
        at repl:1:232
        at Script.Kh (/home/vagrant/git/bdit_flashcrow/node_modules/esm/esm.js:1:291640)
        at Script.d (/home/vagrant/git/bdit_flashcrow/node_modules/esm/esm.js:1:293801)
        at Script.runInThisContext (/home/vagrant/git/bdit_flashcrow/node_modules/esm/esm.js:1:123371)
    SyntaxError: Unexpected token '=>'
        at Function.request (/home/vagrant/git/bdit_flashcrow/node_modules/openid-client/lib/helpers/request.js:27:3)
        at /home/vagrant/git/bdit_flashcrow/node_modules/openid-client/lib/issuer.js:242:38
        at Array.map (<anonymous>)
        at Function.discover (/home/vagrant/git/bdit_flashcrow/node_modules/openid-client/lib/issuer.js:240:22)
        at repl:1
    at maybeSettle (/home/vagrant/git/bdit_flashcrow/node_modules/p-some/index.js:31:11)
    at /home/vagrant/git/bdit_flashcrow/node_modules/p-some/index.js:69:23
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
panva commented 4 years ago

1) openid-client is not an esm module, as per the package.json's lack of "type": "module". 2) you're using esm package which pre-processes the code somehow to make it into an esm? no clue. An arrow function (=>) is available in all supported Node.js runtimes in a number of places throughout the code and 3.12.0 did not introduce anything out of the ordinary in the syntax.

Please take this up with the maintainers of esm. The actions CI is passing on all supported node versions.