From c8b4ad5e832f02617e237b48c2421c160dd119fd Mon Sep 17 00:00:00 2001 From: "Barth, Christopher" Date: Thu, 6 Jul 2017 16:10:54 -0400 Subject: [PATCH] Add support for passport-saml typings --- types/passport-saml/index.d.ts | 77 ++++++++++++++++++++++ types/passport-saml/passport-saml-tests.ts | 32 +++++++++ types/passport-saml/tsconfig.json | 22 +++++++ types/passport-saml/tslint.json | 1 + 4 files changed, 132 insertions(+) create mode 100644 types/passport-saml/index.d.ts create mode 100644 types/passport-saml/passport-saml-tests.ts create mode 100644 types/passport-saml/tsconfig.json create mode 100644 types/passport-saml/tslint.json diff --git a/types/passport-saml/index.d.ts b/types/passport-saml/index.d.ts new file mode 100644 index 0000000000..7ed8606318 --- /dev/null +++ b/types/passport-saml/index.d.ts @@ -0,0 +1,77 @@ +// Type definitions for passport-saml 0.15 +// Project: https://github.com/bergie/passport-saml +// Definitions by: Chris Barth +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import passport = require('passport'); +import express = require('express'); + +export interface CacheItem { + createdAt: Date; + value: any; +} + +export interface CacheProvider { + save(key: string | null, value: any, callback: (err: Error | null, cacheItem: CacheItem) => void | null): void; + get(key: string, callback: (err: Error | null, value: any) => void | null): void; + remove(key: string, callback: (err: Error | null, key: string) => void | null): void; +} + +export type VerifiedCallback = (err: Error | null, user: {}, info: {}) => void; + +export type VerifyWithRequest = (req: express.Request, profile: {}, done: VerifiedCallback) => void; + +export type VerifyWithoutRequest = (profile: {}, done: VerifiedCallback) => void; + +export class Strategy implements passport.Strategy { + constructor(config: SamlConfig, verify: VerifyWithRequest | VerifyWithoutRequest); + authenticate(req: express.Request, options: AuthenticateOptions | AuthorizeOptions): void; + logout(req: express.Request, callback: (err: Error | null, url: string) => void): void; + generateServiceProviderMetadata(decryptionCert: string): string; +} + +export interface SamlConfig { + // Core + callbackUrl?: string; + path: string; + protocol?: string; + host?: string; + entryPoint: string; + issuer: string; + privateCert?: string; + decryptionPvk?: string; + signatureAlgorithm?: 'sha1' | 'sha256' | 'sha512'; + + // Additional SAML behaviors + additionalParams?: {}; + additionalAuthorizeParams?: {}; + identifierFormat?: string; + acceptedClockSkewMs?: number; + attributeConsumingServiceIndex?: string; + disableRequestedAuthnContext?: boolean; + authnContext?: string; + forceAuthn?: boolean; + skipRequestCompression?: boolean; + authnRequestBinding?: string; + + // InResponseTo Validation + validateInResponseTo?: boolean; + requestIdExpirationPeriodMs?: number; + cacheProvider?: CacheProvider; + + // Passport + passReqToCallback?: boolean; + + // Logout + logoutUrl?: string; + additionalLogoutParams?: {}; + logoutCallbackUrl?: string; +} + +export interface AuthenticateOptions extends passport.AuthenticateOptions { + additionalParams?: {}; +} + +export interface AuthorizeOptions extends AuthenticateOptions { + samlFallback?: string; +} diff --git a/types/passport-saml/passport-saml-tests.ts b/types/passport-saml/passport-saml-tests.ts new file mode 100644 index 0000000000..68b1f2a3ff --- /dev/null +++ b/types/passport-saml/passport-saml-tests.ts @@ -0,0 +1,32 @@ +import express = require('express'); +import passport = require('passport'); +import SamlStrategy = require('passport-saml'); + +let samlStrategy = new SamlStrategy.Strategy( + { + path: '/login/callback', + entryPoint: 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php', + issuer: 'passport-saml', + cacheProvider: { + save(key: string, value: {}) { + // save the key with the optional value, invokes the callback with the value saves + }, + get(key: string) { + // invokes 'callback' and passes the value if found, null otherwise + }, + remove(key: string) { + // removes the key from the cache, invokes `callback` with the + // key removed, null if no key is removed + } + } + }, + (profile: {}, done: (err: Error | null, user: {}, info?: {}) => void) => { + let user = {}; + done(null, user); + } +); + +passport.use(samlStrategy); +passport.authenticate('saml', {failureRedirect: '/', failureFlash: true}); + +let metadata = samlStrategy.generateServiceProviderMetadata("decryptionCert"); diff --git a/types/passport-saml/tsconfig.json b/types/passport-saml/tsconfig.json new file mode 100644 index 0000000000..4935a8ff20 --- /dev/null +++ b/types/passport-saml/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-saml-tests.ts" + ] +} diff --git a/types/passport-saml/tslint.json b/types/passport-saml/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/passport-saml/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }