Added passport-client-cert type definition (#16710)

* Added passport-client-cert type definition

* Added passport-client-cert type definition

* Minor fixes for PR
corrected ts version call
changed index accessor for subject and issuer to any. Any makes more sense than anything else, due to potential variation in response.
This commit is contained in:
warnersean
2017-06-01 00:43:45 -05:00
committed by Mohamed Hegazy
parent 86da68051e
commit 8926f7fbff
4 changed files with 72 additions and 0 deletions

35
types/passport-client-cert/index.d.ts vendored Normal file
View File

@@ -0,0 +1,35 @@
// Type definitions for passport-jwt 2.0
// Project: https://github.com/ripjar/passport-client-cert
// Definitions by: Sean Warner <https://github.com/warnersean/>
// 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;

View File

@@ -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);
}));

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }