diff --git a/types/passport-client-cert/index.d.ts b/types/passport-client-cert/index.d.ts new file mode 100644 index 0000000000..5bb80c5027 --- /dev/null +++ b/types/passport-client-cert/index.d.ts @@ -0,0 +1,35 @@ +// Type definitions for passport-jwt 2.0 +// Project: https://github.com/ripjar/passport-client-cert +// Definitions by: Sean Warner +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +import {Strategy as PassportStrategy} from 'passport-strategy'; +import {Request} from 'express'; + +export class Strategy extends PassportStrategy { + constructor(verify: PkiCallback); + constructor(opt: StrategyOptions, verify: PkiCallback | PkiCallbackWithRequest); +} + +export interface StrategyOptions { + passReqToCallback?: boolean; +} + +export type PkiCallback = (payload: ClientCert, done: PkiVerifiedCallback) => void; + +export type PkiCallbackWithRequest = (req: Request, payload: ClientCert, done: PkiVerifiedCallback) => void; + +export interface ClientCert { + exponent: string; + fingerprint: string; + issuer: any; + modulus: string; + raw: Uint8Array; + serialNumber: string; + subject: any; + valid_from: string; + valid_to: string; +} + +export type PkiVerifiedCallback = (error: any, user?: any, info?: any) => void; diff --git a/types/passport-client-cert/passport-client-cert-tests.ts b/types/passport-client-cert/passport-client-cert-tests.ts new file mode 100644 index 0000000000..256d2ddcd6 --- /dev/null +++ b/types/passport-client-cert/passport-client-cert-tests.ts @@ -0,0 +1,14 @@ +import * as passport from "passport"; +import {ClientCert, PkiVerifiedCallback, Strategy as ClientCertStrategy} from "passport-client-cert"; + +passport.use(new ClientCertStrategy( (clientCert: ClientCert, done: PkiVerifiedCallback) => { + let cn = clientCert.subject.cn; + let user = null; + + // The CN will typically be checked against a database + if (cn === 'test-cn') { + user = { name: 'Test User' }; + } + + done(null, user); +})); diff --git a/types/passport-client-cert/tsconfig.json b/types/passport-client-cert/tsconfig.json new file mode 100644 index 0000000000..614afd9842 --- /dev/null +++ b/types/passport-client-cert/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "passport-client-cert-tests.ts" + ] +} diff --git a/types/passport-client-cert/tslint.json b/types/passport-client-cert/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/passport-client-cert/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }