From 222ad6fd0d744790d9a7173a8a1a97850b140cb3 Mon Sep 17 00:00:00 2001 From: Jeffrey Barrus <1044815+jbarrus@users.noreply.github.com> Date: Mon, 7 Oct 2019 22:20:59 -0600 Subject: [PATCH 1/3] add typescript types --- index.d.ts | 24 +++++++++++++++++ package-lock.json | 68 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 93 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 00000000..84b28fd5 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,24 @@ +// Type definitions for express-openid-connect + +import { AuthorizationParameters, TokenSet } from 'openid-client'; +import { Request, RequestHandler } from 'express'; + +interface AuthParams { + issuerBaseURL?: string; + baseURL?: string; + clientID?: string; + clientSecret?: string; + clockTolerance?: number; + getUser?: (tokenSet: TokenSet) => any; + required?: boolean | ((request: Request) => boolean); + errorOnRequiredAuth?: boolean; + idpLogout?: boolean; + auth0Logout?: boolean; + routes?: boolean; + redirectUriPath?: string; + authorizationParams?: AuthorizationParameters +} + +export function auth(params?: AuthParams): RequestHandler; +export function requiresAuth(): RequestHandler; +export function unauthorizedHandler(): RequestHandler; diff --git a/package-lock.json b/package-lock.json index 4a22da30..c843203a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -117,6 +117,74 @@ "defer-to-connect": "^1.0.1" } }, + "@types/body-parser": { + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.17.1.tgz", + "integrity": "sha512-RoX2EZjMiFMjZh9lmYrwgoP9RTpAjSHiJxdp4oidAQVO02T7HER3xj9UKue5534ULWeqVEkujhWcyvUce+d68w==", + "dev": true, + "requires": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "@types/connect": { + "version": "3.4.32", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.32.tgz", + "integrity": "sha512-4r8qa0quOvh7lGD0pre62CAb1oni1OO6ecJLGCezTmhQ8Fz50Arx9RUszryR8KlgK6avuSXvviL6yWyViQABOg==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/express": { + "version": "4.17.1", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.1.tgz", + "integrity": "sha512-VfH/XCP0QbQk5B5puLqTLEeFgR8lfCJHZJKkInZ9mkYd+u8byX0kztXEQxEk4wZXJs8HI+7km2ALXjn4YKcX9w==", + "dev": true, + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "*", + "@types/serve-static": "*" + } + }, + "@types/express-serve-static-core": { + "version": "4.16.9", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.16.9.tgz", + "integrity": "sha512-GqpaVWR0DM8FnRUJYKlWgyARoBUAVfRIeVDZQKOttLFp5SmhhF9YFIYeTPwMd/AXfxlP7xVO2dj1fGu0Q+krKQ==", + "dev": true, + "requires": { + "@types/node": "*", + "@types/range-parser": "*" + } + }, + "@types/mime": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.1.tgz", + "integrity": "sha512-FwI9gX75FgVBJ7ywgnq/P7tw+/o1GUbtP0KzbtusLigAOgIgNISRK0ZPl4qertvXSIE8YbsVJueQ90cDt9YYyw==", + "dev": true + }, + "@types/node": { + "version": "12.7.11", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.11.tgz", + "integrity": "sha512-Otxmr2rrZLKRYIybtdG/sgeO+tHY20GxeDjcGmUnmmlCWyEnv2a2x1ZXBo3BTec4OiTXMQCiazB8NMBf0iRlFw==", + "dev": true + }, + "@types/range-parser": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.3.tgz", + "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==", + "dev": true + }, + "@types/serve-static": { + "version": "1.13.3", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.3.tgz", + "integrity": "sha512-oprSwp094zOglVrXdlo/4bAHtKTAxX6VT8FOZlBKrmyLbNvE1zxZyJ6yikMVtHIvwP45+ZQGJn+FdXGKTozq0g==", + "dev": true, + "requires": { + "@types/express-serve-static-core": "*", + "@types/mime": "*" + } + }, "abab": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.2.tgz", diff --git a/package.json b/package.json index a81c6964..3b448f4a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "url-join": "^4.0.1" }, "devDependencies": { + "@types/express": "^4.17.1", "body-parser": "^1.19.0", "chai": "^4.2.0", "cookie-session": "^2.0.0-beta.3", From c5e2c5de2738973ba0a297f60fbb02ea4c79d2c0 Mon Sep 17 00:00:00 2001 From: Jeffrey Barrus <1044815+jbarrus@users.noreply.github.com> Date: Tue, 8 Oct 2019 20:37:47 -0600 Subject: [PATCH 2/3] typescript definition updates based on PR feedback --- index.d.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/index.d.ts b/index.d.ts index 84b28fd5..a365faed 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,22 +3,25 @@ import { AuthorizationParameters, TokenSet } from 'openid-client'; import { Request, RequestHandler } from 'express'; -interface AuthParams { - issuerBaseURL?: string; +interface ConfigParams { + auth0Logout?: boolean; + authorizationParams?: AuthorizationParameters baseURL?: string; clientID?: string; clientSecret?: string; clockTolerance?: number; - getUser?: (tokenSet: TokenSet) => any; - required?: boolean | ((request: Request) => boolean); errorOnRequiredAuth?: boolean; + getUser?: (tokenSet: TokenSet) => undefined | object; idpLogout?: boolean; - auth0Logout?: boolean; - routes?: boolean; + idTokenAlg?: string; + issuerBaseURL?: string; + loginPath?: string; + logoutPath?: string; redirectUriPath?: string; - authorizationParams?: AuthorizationParameters + required?: boolean | ((request: Request) => boolean); + routes?: boolean; } -export function auth(params?: AuthParams): RequestHandler; +export function auth(params?: ConfigParams): RequestHandler; export function requiresAuth(): RequestHandler; export function unauthorizedHandler(): RequestHandler; From ed1ab52059583decc9676fa5cffa50409c7e6b03 Mon Sep 17 00:00:00 2001 From: Jeffrey Barrus <1044815+jbarrus@users.noreply.github.com> Date: Wed, 9 Oct 2019 22:06:45 -0600 Subject: [PATCH 3/3] set explicit type on getUser function --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index a365faed..61322fb6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for express-openid-connect -import { AuthorizationParameters, TokenSet } from 'openid-client'; +import { AuthorizationParameters, TokenSet, UserinfoResponse } from 'openid-client'; import { Request, RequestHandler } from 'express'; interface ConfigParams { @@ -11,7 +11,7 @@ interface ConfigParams { clientSecret?: string; clockTolerance?: number; errorOnRequiredAuth?: boolean; - getUser?: (tokenSet: TokenSet) => undefined | object; + getUser?: (tokenSet: TokenSet) => undefined | UserinfoResponse; idpLogout?: boolean; idTokenAlg?: string; issuerBaseURL?: string;