Skip to content

Commit

Permalink
feat: added TypeScript definitions (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
panva authored Sep 17, 2019
1 parent 7071340 commit 5adf5a8
Show file tree
Hide file tree
Showing 42 changed files with 2,140 additions and 42 deletions.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ oidc-provider allows to be extended and configured in various ways to fit a vari
the [available configuration](/docs/README.md).

```js
const Provider = require('oidc-provider');
const { Provider } = require('oidc-provider');
const configuration = {
// ... see available options /docs
clients: [{
Expand All @@ -125,6 +125,33 @@ const server = oidc.listen(3000, () => {
});
```

```ts
import * as oidc from 'oidc-provider';

const configuration = {
// ... see available options /docs
clients: [{
client_id: 'foo',
client_secret: 'bar',
redirect_uris: ['http://lvh.me:8080/cb'],
// + other client properties
}],
};

const provider = new oidc.Provider('http://localhost:3000', configuration);

// express/nodejs style application callback (req, res, next) for use with express apps, see /examples/express.js
provider.callback

// koa application for use with koa apps, see /examples/koa.js
provider.app

// or just expose a server standalone, see /examples/standalone.js
const server = provider.listen(3000, () => {
console.log('oidc-provider listening on port 3000, check http://localhost:3000/.well-known/openid-configuration');
});
```


## Recipes
Collection of useful configurations use cases are available over at [recipes](/recipes).
Expand Down
2 changes: 1 addition & 1 deletion certification/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const https = require('https');
const pem = require('https-pem');
const render = require('koa-ejs');

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

Expand Down
4 changes: 2 additions & 2 deletions certification/fapi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const jose = require('@panva/jose');
const helmet = require('koa-helmet');
const pem = require('https-pem');

const Server = require('../../lib'); // require('oidc-provider');
const { Provider } = require('../../lib'); // require('oidc-provider');

const OFFICIAL_CERTIFICATION = 'https://www.certification.openid.net';
const { PORT = 3000, ISSUER = `http://localhost:${PORT}`, SUITE_BASE_URL = OFFICIAL_CERTIFICATION } = process.env;
Expand All @@ -21,7 +21,7 @@ const JWK_PKJWTTWO = jose.JWK.asKey(readFileSync(path.join(__dirname, 'pkjwttwo.
const JWK_MTLSONE = jose.JWK.asKey(readFileSync(path.join(__dirname, 'mtlsone.key')), { x5c: [normalize(readFileSync(path.join(__dirname, 'mtlsone.crt')))], alg: 'PS256', use: 'sig' }).toJWK();
const JWK_MTLSTWO = jose.JWK.asKey(readFileSync(path.join(__dirname, 'mtlstwo.key')), { x5c: [normalize(readFileSync(path.join(__dirname, 'mtlstwo.crt')))], alg: 'PS256', use: 'sig' }).toJWK();

const fapi = new Server(ISSUER, {
const fapi = new Provider(ISSUER, {
acrValues: ['urn:mace:incommon:iap:silver'],
routes: {
userinfo: '/accounts',
Expand Down
2 changes: 1 addition & 1 deletion certification/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const set = require('lodash/set');
const render = require('koa-ejs');
const helmet = require('koa-helmet');

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

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ If you or your business use oidc-provider, please consider becoming a [sponsor][
## Basic configuration example

```js
const Provider = require('oidc-provider');
const { Provider } = require('oidc-provider');
const configuration = {
// ... see the available options in Configuration options section
features: {
Expand Down
2 changes: 0 additions & 2 deletions docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ loaded client or session.
| `registration_read.error` | `(ctx, error)` | ... whenever a handled error is encountered in the GET `registration` endpoint |
| `registration_update.error` | `(ctx, error)` | ... whenever a handled error is encountered in the PUT `registration` endpoint |
| `registration_update.success` | `(ctx, client)` | ... with every successful update client registration request |
| `replay_detection.destroyed` | `(replay)` | ... whenever replay detection document is destroyed |
| `replay_detection.saved` | `(replay)` | ... whenever replay detection document is saved |
| `revocation.error` | `(ctx, error)` | ... whenever a handled error is encountered in the `revocation` endpoint |
| `server_error` | `(ctx, error)` | ... whenever an exception is thrown or promise rejected from either the Provider or your provided adapters. If it comes from the library you should probably report it |
| `session.destroyed` | `(session)` | ... whenever session is destroyed |
Expand Down
2 changes: 1 addition & 1 deletion example/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const set = require('lodash/set');
const express = require('express'); // eslint-disable-line import/no-unresolved
const helmet = require('helmet');

const Provider = require('../lib'); // require('oidc-provider');
const { Provider } = require('../lib'); // require('oidc-provider');

const Account = require('./support/account');
const configuration = require('./support/configuration');
Expand Down
2 changes: 1 addition & 1 deletion example/koa.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const render = require('koa-ejs');
const helmet = require('koa-helmet');
const mount = require('koa-mount');

const Provider = require('../lib'); // require('oidc-provider');
const { Provider } = require('../lib'); // require('oidc-provider');

const Account = require('./support/account');
const configuration = require('./support/configuration');
Expand Down
3 changes: 1 addition & 2 deletions example/my_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class MyAdapter {
* - kind {string} - "Interaction" fixed string value
* - exp {number} - timestamp of the interaction's expiration
* - iat {number} - timestamp of the interaction's creation
* - uid {number} - the uid of the authorizing client's established session
* - uid {string} - the uid of the authorizing client's established session
* - returnTo {string} - after resolving interactions send the user-agent to this url
* - params {object} - parsed recognized parameters object
* - lastSubmission {object} - previous interaction result submission
Expand All @@ -141,7 +141,6 @@ class MyAdapter {
* - kind {string} - "ReplayDetection" fixed string value
* - exp {number} - timestamp of the replay object cache expiration
* - iat {number} - timestamp of the replay object cache's creation
* - replay {object} - the object replay prevention is calculated from
*/
}

Expand Down
2 changes: 1 addition & 1 deletion example/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const set = require('lodash/set');
const render = require('koa-ejs');
const helmet = require('koa-helmet');

const Provider = require('../lib'); // require('oidc-provider');
const { Provider } = require('../lib'); // require('oidc-provider');

const Account = require('./support/account');
const configuration = require('./support/configuration');
Expand Down
2 changes: 0 additions & 2 deletions lib/actions/authorization/device_authorization_response.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module.exports = async function deviceAuthorizationResponse(ctx, next) {

const dc = new ctx.oidc.provider.DeviceCode({
client: ctx.oidc.client,
codeChallenge: ctx.oidc.params.code_challenge,
codeChallengeMethod: ctx.oidc.params.code_challenge_method,
deviceInfo: deviceInfo(ctx),
grantId: ctx.oidc.uid,
params: ctx.oidc.params.toPlainObject(),
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const errors = require('./helpers/errors');
const { DYNAMIC_SCOPE_LABEL } = require('./consts');

module.exports = Provider;
module.exports.Provider = Provider;
module.exports.errors = errors;
module.exports.DYNAMIC_SCOPE_LABEL = DYNAMIC_SCOPE_LABEL;
module.exports.interactionPolicy = require('./helpers/interaction_policy');
2 changes: 1 addition & 1 deletion lib/models/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module.exports = function getSession(provider) {
this.destroyed = true; // TODO:
}

async resetIdentifier() {
resetIdentifier() {
this.oldId = this.id;
this.id = nanoid();
this.touched = true;
Expand Down
2 changes: 2 additions & 0 deletions lib/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class Provider extends events.EventEmitter {

const grantParams = new Set(['grant_type']);
grantTypeHandlers.set(name, handler);

if (dupes && typeof dupes === 'string') {
grantTypeDupes.set(name, new Set([dupes]));
} else if (dupes && (Array.isArray(dupes) || dupes instanceof Set)) {
Expand All @@ -139,6 +140,7 @@ class Provider extends events.EventEmitter {
} else if (params && (Array.isArray(params) || params instanceof Set)) {
params.forEach(Set.prototype.add.bind(grantParams));
}

grantTypeParams.set(name, grantParams);
grantParams.forEach(Set.prototype.add.bind(grantTypeParams.get(undefined)));
}
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@
"author": "Filip Skokan <panva.ip@gmail.com>",
"files": [
"lib",
"docs/*.md",
"recipes/*.md"
"types/index.d.ts"
],
"main": "lib/index.js",
"types": "types/index.d.ts",
"scripts": {
"coverage": "nyc node ./test/run",
"heroku-postbuild": "npm install mongodb@^3.0.0 openid-client@^3.0.0",
"lint": "eslint lib example certification test",
"lint": "eslint lib example certification test && dtslint --onlyTestTsNext types",
"lint-fix": "eslint lib example certification test --fix",
"test": "node ./test/run"
},
"dependencies": {
"@koa/cors": "^3.0.0",
"@panva/jose": "^1.8.0",
"@types/cookies": "^0.7.2",
"@types/koa": "^2.0.49",
"@types/node": "^12.7.4",
"bowser": "^2.5.3",
"debug": "^4.1.1",
"ejs": "^2.6.2",
Expand All @@ -63,6 +66,7 @@
"base64url": "^3.0.1",
"chai": "^4.2.0",
"clear-module": "^4.0.0",
"dtslint": "^0.9.6",
"eslint": "^6.2.2",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.18.2",
Expand Down
2 changes: 1 addition & 1 deletion test/body_parser/body_parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const upstreamParser = require('koa-body');
const sinon = require('sinon');
const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('body parser', () => {
afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/client_auth/client_auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const cloneDeep = require('lodash/cloneDeep');

const runtimeSupport = require('../../lib/helpers/runtime_support');
const nanoid = require('../../lib/helpers/nanoid');
const Provider = require('../../lib');
const { Provider } = require('../../lib');
const bootstrap = require('../test_helper');
const clientKey = require('../client.sig.key');
const JWT = require('../../lib/helpers/jwt');
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/account_find_by_id.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('default findAccount behavior', () => {
it('returns a promise', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/client_metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const pull = require('lodash/pull');
const cloneDeep = require('lodash/cloneDeep');

const runtimeSupport = require('../../lib/helpers/runtime_support');
const Provider = require('../../lib');
const { Provider } = require('../../lib');
const { whitelistedJWA } = require('../default.config');
const mtlsKeys = require('../jwks/jwks.json');

Expand Down
2 changes: 1 addition & 1 deletion test/configuration/constructor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('Provider configuration', () => {
describe('clients', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/custom_client_metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { expect } = require('chai');
const sinon = require('sinon');

const Provider = require('../../lib');
const { Provider } = require('../../lib');
const { InvalidClientMetadata } = require('../../lib/helpers/errors');

describe('extraClientMetadata configuration', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/interaction_url.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('pathFor related behaviors', () => {
it('throws an Error when invalid route path is requested', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/issuer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { strict: assert } = require('assert');

const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('Provider issuer configuration', () => {
it('validates the issuer input to be present and valid', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/keystore_configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const jose = require('@panva/jose');
const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('configuration.jwks', () => {
beforeEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/omit_algs.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { expect } = require('chai');
const jose = require('@panva/jose');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('Provider declaring supported algorithms', () => {
it('validates the configuration properties', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/pairwise.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('Provider configuration', () => {
it('validates subjectTypes members', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/request_uris.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('client.requestUris', () => {
it('defaults to empty array when registration of them is a must', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/response_types.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('response_types Provider configuration', () => {
it('fixes common issues', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/scopes_claims.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('custom claims', () => {
it('allows for claims to be added under openid scope using array syntax', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/device_code/device_code.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');
const bootstrap = require('../test_helper');

describe('configuration features.deviceFlow', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/jwt_introspection/jwt_introspection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { expect } = require('chai');

const bootstrap = require('../test_helper');
const JWT = require('../../lib/helpers/jwt');
const Provider = require('../../lib');
const { Provider } = require('../../lib');

const route = '/token/introspection';

Expand Down
2 changes: 1 addition & 1 deletion test/provider/provider_instance.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { expect } = require('chai');
const sinon = require('sinon');

const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('provider instance', () => {
context('draft/experimental spec warnings', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/pushed_request_objects/pushed_request_objects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const sinon = require('sinon');

const JWT = require('../../lib/helpers/jwt');
const bootstrap = require('../test_helper');
const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('Pushed Request Object', () => {
before(bootstrap(__dirname));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const sinon = require('sinon');
const { expect } = require('chai');

const bootstrap = require('../test_helper');
const Provider = require('../../lib');
const { Provider } = require('../../lib');

describe('OAuth 2.0 Dynamic Client Registration Management Protocol', () => {
before(bootstrap(__dirname));
Expand Down
2 changes: 1 addition & 1 deletion test/registration_policies/registration_policies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const sinon = require('sinon');
const { expect } = require('chai');

const bootstrap = require('../test_helper');
const Provider = require('../../lib');
const { Provider } = require('../../lib');

const fail = () => { throw new Error('expected promise to be rejected'); };

Expand Down
2 changes: 1 addition & 1 deletion test/request/jwt_request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const jose = require('@panva/jose');
const sinon = require('sinon');
const { expect } = require('chai');

const Provider = require('../../lib');
const { Provider } = require('../../lib');
const JWT = require('../../lib/helpers/jwt');
const bootstrap = require('../test_helper');

Expand Down
Loading

0 comments on commit 5adf5a8

Please sign in to comment.