Add types for passport-windowsauth (#29630)

* Add types for passport-windowsauth

* Use class instead of interface for strategy-windowsauth
This commit is contained in:
Emily Marigold Klassen
2018-10-12 09:09:27 -07:00
committed by Andy
parent 66d218c459
commit 52d1975b92
4 changed files with 101 additions and 0 deletions

49
types/passport-windowsauth/index.d.ts vendored Normal file
View File

@@ -0,0 +1,49 @@
// Type definitions for passport-windowsauth 3.0
// Project: https://github.com/auth0/passport-windowsauth#readme
// Definitions by: Emily Marigold Klassen <https://github.com/forivall>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as express from 'express';
import * as passport from 'passport';
import * as ldapjs from 'ldapjs';
import { TlsOptions } from 'tls';
declare namespace windowsauth {
interface Options {
ldap?: {
url?: string
maxConnections?: number
base?: string
bindDN?: string
bindCredentials?: string
tlsOptions?: TlsOptions;
reconnect?: boolean | {
initialDelay?: number,
maxDelay?: number,
failAfter?: number
};
timeout?: number;
connectTimeout?: number;
idleTimeout?: number;
binder?: ldapjs.Client
client?: ldapjs.Client
};
integrated?: boolean;
getUserNameFromHeader?(req: express.Request): string;
passReqToCallback?: boolean;
usernameField?: string;
passwordField?: string;
}
type Verified = (err: Error | undefined | null, user?: object, info?: object) => void;
type Verify = (profile: passport.Profile, done: Verified) => void;
type VerifyWithReq = (req: express.Request, profile: passport.Profile, done: Verified) => void;
}
declare class windowsauth extends passport.Strategy {
constructor(options: windowsauth.Options & {passReqToCallback: true}, verify: windowsauth.VerifyWithReq);
constructor(options: windowsauth.Options, verify: windowsauth.Verify);
constructor(verify: windowsauth.Verify);
}
export = windowsauth;

View File

@@ -0,0 +1,28 @@
import * as passport from 'passport';
import * as WindowsStrategy from 'passport-windowsauth';
const auth = new passport.Authenticator();
auth.use(new WindowsStrategy({integrated: true}, (profile, done) => {
console.log(profile);
done(null, profile);
}));
passport.use(new WindowsStrategy({
ldap: {
url: 'ldap://wellscordoba.wellscordobabank.com/DC=wellscordobabank,DC=com',
base: 'DC=wellscordobabank,DC=com',
bindDN: 'someAccount',
bindCredentials: 'andItsPass'
}
}, (profile, done) => {
console.log('logged in', profile.id);
done(null, profile);
}));
passport.use(new WindowsStrategy({
integrated: true,
passReqToCallback: true
}, (req, profile, done) => {
console.log('logged in', req, profile.id);
done(null, profile);
}));

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"passport-windowsauth-tests.ts"
]
}

View File

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