Skip to content

Commit

Permalink
refactor!: oidc-provider is now an ESM-only module
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `oidc-provider` is now an ESM-only module, it must now be imported using the `import` declaration or the `import()` syntax, the `Provider` constructor is the module's default export, the `errors` and `interactionPolicy` exports are the package's named exports. There is no `Provider` named export.
  • Loading branch information
panva committed Dec 1, 2022
1 parent bd0e78c commit 3c5ebe1
Show file tree
Hide file tree
Showing 402 changed files with 3,032 additions and 2,967 deletions.
11 changes: 9 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
"extends": "airbnb-base",
"rules": {
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-underscore-dangle": ["error", { "allow": ["_claim_names", "_claim_sources", "_matchedRouteName"] }],
"no-underscore-dangle": ["error", { "allow": ["_claim_names", "_claim_sources", "_matchedRouteName", "__dirname"] }],
"import/order": ["error", { "groups": ["builtin", "external", "internal", "parent", "sibling", "index"], "newlines-between": "always" }],
"symbol-description": ["off"],
"import/extensions": ["error", "ignorePackages"]
},
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": "latest"
"ecmaVersion": "latest",
"requireConfigFile": false,
"babelOptions": {
"plugins": [
"@babel/plugin-syntax-import-assertions"
]
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ jobs:
sed -i -e 's/mtls.fapi.panva.cz/172.17.0.1:3000/g' certification/fapi/plan.json
sed -i -e 's/fapi.panva.cz/172.17.0.1:3000/g' certification/fapi/plan.json
- name: Run the plan
run: npx mocha --delay --timeout 0 --retries 0 certification/runner
run: npx mocha --timeout 0 --retries 1 certification/runner
env:
NODE_TLS_REJECT_UNAUTHORIZED: 0
- name: Upload test artifacts
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ oidc-provider can be mounted to existing connect, express, fastify, hapi, or koa
various ways to fit a variety of uses. See the [documentation](/docs/README.md).

```js
const { Provider } = require('oidc-provider');
import Provider from 'oidc-provider';
const configuration = {
// ... see /docs for available configuration
clients: [{
Expand Down
31 changes: 17 additions & 14 deletions certification/fapi/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
/* eslint-disable no-console */

const { readFileSync } = require('node:fs');
const path = require('node:path');
const { randomBytes, randomUUID } = require('node:crypto');
const https = require('node:https');
const { promisify } = require('node:util');
const { URL } = require('node:url');

const jose = require('jose2');
const helmet = require('helmet');
const selfsigned = require('selfsigned').generate();

const { Provider, errors } = require('../../lib/index.js'); // require('oidc-provider');
const MemoryAdapter = require('../../lib/adapters/memory_adapter.js');

import { readFileSync } from 'node:fs';
import path from 'node:path';
import { randomBytes, randomUUID } from 'node:crypto';
import https from 'node:https';
import { promisify } from 'node:util';
import { URL } from 'node:url';

import { dirname } from 'desm';
import jose from 'jose2';
import helmet from 'helmet';
import { generate } from 'selfsigned';

import Provider, { errors } from '../../lib/index.js'; // from 'oidc-provider';
import MemoryAdapter from '../../lib/adapters/memory_adapter.js';

const __dirname = dirname(import.meta.url);
const selfsigned = generate();
const OFFICIAL_CERTIFICATION = 'https://www.certification.openid.net';
const { PORT = 3000, ISSUER = `http://localhost:${PORT}`, SUITE_BASE_URL = OFFICIAL_CERTIFICATION } = process.env;

Expand Down
6 changes: 2 additions & 4 deletions certification/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable global-require */

if (process.env.FAPI) {
require('./fapi/index.js');
await import('./fapi/index.js');
} else {
require('./oidc/index.js');
await import('./oidc/index.js');
}
9 changes: 5 additions & 4 deletions certification/oidc/configuration.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const crypto = require('node:crypto');
import crypto from 'node:crypto';

const pkg = require('../../package.json');
const enabledJWA = JSON.parse(JSON.stringify(require('../../lib/consts/jwa.js')));
import pkg from '../../package.json' assert { type: 'json' };

const enabledJWA = JSON.parse(JSON.stringify(await import('../../lib/consts/jwa.js')));

const timeout = parseInt(process.env.TIMEOUT, 10);
const clientAuthMethods = [
Expand All @@ -13,7 +14,7 @@ const clientAuthMethods = [
'self_signed_tls_client_auth',
];

module.exports = {
export default {
interactions: {
url(ctx, interaction) {
return `/interaction/${interaction.uid}`;
Expand Down
19 changes: 11 additions & 8 deletions certification/oidc/docker.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
/* eslint-disable no-console */

const path = require('node:path');
const https = require('node:https');
import path from 'node:path';
import https from 'node:https';

const selfsigned = require('selfsigned').generate();
const render = require('@koa/ejs');
import { generate } from 'selfsigned';
import render from '@koa/ejs';
import { dirname } from 'desm';

const { Provider } = require('../../lib/index.js'); // require('oidc-provider');
const Account = require('../../example/support/account.js');
const routes = require('../../example/routes/koa.js');
import Provider from '../../lib/index.js'; // from 'oidc-provider';
import Account from '../../example/support/account.js';
import routes from '../../example/routes/koa.js';

const configuration = require('./configuration.js');
import configuration from './configuration.js';

const selfsigned = generate();
const { PORT = 3000, ISSUER = `http://localhost:${PORT}` } = process.env;
configuration.findAccount = Account.findAccount;

const provider = new Provider(ISSUER, configuration);
const __dirname = dirname(import.meta.url);

// don't wanna re-bundle the interactions so just insert the login amr and acr as static whenever
// login is submitted, usually you would submit them from your interaction
Expand Down
4 changes: 2 additions & 2 deletions certification/oidc/heroku_mongo_adapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const MongoAdapter = require('../../example/adapters/mongodb.js');
import MongoAdapter from '../../example/adapters/mongodb.js';

class HerokuExampleAdapter extends MongoAdapter {
async upsert(_id, payload, expiresIn) {
Expand All @@ -12,4 +12,4 @@ class HerokuExampleAdapter extends MongoAdapter {
}
}

module.exports = HerokuExampleAdapter;
export default HerokuExampleAdapter;
31 changes: 17 additions & 14 deletions certification/oidc/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
/* eslint-disable no-console */

const { promisify } = require('node:util');
const path = require('node:path');
const crypto = require('node:crypto');
import { promisify } from 'node:util';
import path from 'node:path';
import crypto from 'node:crypto';

const render = require('@koa/ejs');
const helmet = require('helmet');
import { dirname } from 'desm';
import render from '@koa/ejs';
import helmet from 'helmet';

const { Provider } = require('../../lib/index.js'); // require('oidc-provider');
const Account = require('../../example/support/account.js');
const routes = require('../../example/routes/koa.js');
import Provider from '../../lib/index.js'; // from 'oidc-provider';
import Account from '../../example/support/account.js';
import routes from '../../example/routes/koa.js';

const configuration = require('./configuration.js');
import configuration from './configuration.js';

const __dirname = dirname(import.meta.url);

const { GOOGLE_CLIENT_ID, PORT = 3000, ISSUER = `http://localhost:${PORT}` } = process.env;
configuration.findAccount = Account.findAccount;

let server;

(async () => {
try {
let adapter;
if (process.env.MONGODB_URI) {
adapter = require('./heroku_mongo_adapter.js'); // eslint-disable-line global-require
({ default: adapter } = await import('./heroku_mongo_adapter.js'));
await adapter.connect();
}

const provider = new Provider(ISSUER, { adapter, ...configuration });

if (GOOGLE_CLIENT_ID) {
const openid = require('openid-client'); // eslint-disable-line global-require, import/no-unresolved
const openid = await import('openid-client'); // eslint-disable-line import/no-unresolved
const google = await openid.Issuer.discover('https://accounts.google.com/.well-known/openid-configuration');
const googleClient = new google.Client({
client_id: GOOGLE_CLIENT_ID,
Expand Down Expand Up @@ -140,8 +143,8 @@ let server;
process.exit(0);
});
});
})().catch((err) => {
} catch (err) {
if (server && server.listening) server.close();
console.error(err);
process.exitCode = 1;
});
}
18 changes: 9 additions & 9 deletions certification/runner/api.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* eslint-disable no-await-in-loop */
const { strict: assert } = require('node:assert');
const { createWriteStream } = require('node:fs');
const stream = require('node:stream');
const { promisify } = require('node:util');
import { strict as assert } from 'node:assert';
import { createWriteStream } from 'node:fs';
import stream from 'node:stream';
import { promisify } from 'node:util';

const Got = require('got');
const ms = require('ms');
import Got from 'got';
import ms from 'ms';

const pipeline = promisify(stream.pipeline);
import debug from './debug.js';

const debug = require('./debug.js');
const pipeline = promisify(stream.pipeline);

const FINISHED = new Set(['FINISHED']);
const RESULTS = new Set(['REVIEW', 'PASSED', 'SKIPPED']);
Expand Down Expand Up @@ -155,4 +155,4 @@ class API {
}
}

module.exports = API;
export default API;
6 changes: 3 additions & 3 deletions certification/runner/debug.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Debug from 'debug';

if (!('DEBUG' in process.env)) {
process.env.DEBUG = 'runner';
}

const debug = require('debug')('runner');

module.exports = debug;
export default new Debug('runner');
26 changes: 13 additions & 13 deletions certification/runner/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-env mocha */
/* eslint-disable no-bitwise, func-names, no-console, no-restricted-syntax, no-await-in-loop, no-multi-assign, max-len */

const { strict: assert } = require('node:assert');
const fs = require('node:fs');
import { strict as assert } from 'node:assert';
import fs from 'node:fs';

const debug = require('./debug.js');
const API = require('./api.js');
import debug from './debug.js';
import API from './api.js';

const {
SUITE_ACCESS_TOKEN,
Expand Down Expand Up @@ -59,11 +59,13 @@ if (VARIANT.client_registration === 'dynamic_client') {
delete configuration.alias;
}

runner.createTestPlan({
configuration,
planName: PLAN_NAME,
variant: JSON.stringify(VARIANT),
}).then((plan) => {
try {
const plan = await runner.createTestPlan({
configuration,
planName: PLAN_NAME,
variant: JSON.stringify(VARIANT),
});

const { id: PLAN_ID, modules: MODULES } = plan;

debug('Created test plan, new id %s', PLAN_ID);
Expand Down Expand Up @@ -98,9 +100,7 @@ runner.createTestPlan({
});
}
});

run();
}).catch((err) => {
} catch (err) {
console.error(err);
process.exitCode = 1;
});
}
Loading

0 comments on commit 3c5ebe1

Please sign in to comment.