Merge pull request #17814 from cjbarth/passport-saml

PASSPORT: Add support for passport-saml typings
This commit is contained in:
Ryan Cavanaugh
2017-07-12 10:41:44 -07:00
committed by GitHub
4 changed files with 132 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
// Type definitions for passport-saml 0.15
// Project: https://github.com/bergie/passport-saml
// Definitions by: Chris Barth <https://github.com/cjbarth/>
// 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;
}
@@ -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");
+22
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-saml-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }