mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
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:
committed by
Mohamed Hegazy
parent
86da68051e
commit
8926f7fbff
+35
@@ -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;
|
||||
@@ -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);
|
||||
}));
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user