passport-saml-metadata: new package (#43964)

* feat(passport-saml-metadata): Define new Package

refact: Better Interfaces

* refact: Clean Overeager Generics

* style: mirror lib hierarchy

Co-authored-by: gfournier <gfournier@focusoptimization.com>
This commit is contained in:
Gabriel Fournier 2020-04-17 18:57:24 -04:00 committed by GitHub
parent 031f592cc7
commit 5cfcaa22e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,7 @@
// Type definitions for passport-saml-metadata 2.2
// Project: https://github.com/compwright/passport-saml-metadata#readme
// Definitions by: Gabriel Fournier <https://github.com/carboneater>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.8
export * from "./src";

View File

@ -0,0 +1,21 @@
import { claimsToCamelCase, fetch, metadata, MetadataReader, toPassportConfig } from "passport-saml-metadata/src";
import { Profile, Strategy, VerifiedCallback } from "passport-saml";
// From README Example
fetch({ url: "https:saml.test.com/metadata.xml" }).then(
(reader) => {
const config = toPassportConfig(reader);
config.protocol = 'saml2';
new Strategy(config, (profile: Profile, done: VerifiedCallback) => {
profile = claimsToCamelCase(profile, reader.claimSchema);
done(null, profile);
});
}
);
const reader = new MetadataReader("xml string");
const otherReader = new MetadataReader("Other String", {authnRequestBinding: "HTTP-POST", throwExceptions: true});
const config = toPassportConfig(reader, {multipleCerts : true});
metadata(config)(); // matches the code, not the doc

View File

@ -0,0 +1,12 @@
export interface FetchAxiosConfig {
backupStore: Map<string, string>;
responseType: string;
timeout: number;
}
export type FetchConfig = {
client?: {get(url: string, params?: Partial<FetchAxiosConfig>): Promise<{data: string}>};
url: string;
} & Partial<FetchAxiosConfig>;
export function fetch(config: FetchConfig): Promise<string>;

View File

@ -0,0 +1,7 @@
import { FetchConfig } from "./fetch";
import { MetadataReader } from "./reader";
export function fetch(config: FetchConfig): Promise<MetadataReader>;
export { metadata } from "./metadata";
export { claimsToCamelCase, toPassportConfig } from "./passport";
export { MetadataReader } from "./reader";

View File

@ -0,0 +1,3 @@
import { SamlConfig } from "passport-saml";
export function metadata(config: SamlConfig): (() => void);

View File

@ -0,0 +1,6 @@
import { SamlConfig } from "passport-saml";
import { MetadataReader } from "./reader";
export function claimsToCamelCase(claims: any, claimSchema: any): any;
export function toPassportConfig(reader?: MetadataReader, options?: { multipleCerts: boolean }): SamlConfig;

View File

@ -0,0 +1,15 @@
export interface MetadataConstructorOptions {
authnRequestBinding: string;
throwExceptions: boolean;
}
export class MetadataReader {
constructor(metadata: string, options?: Partial<MetadataConstructorOptions>);
get claimSchema(): {[name: string]: { camelCase: string; description: string; name: string; }};
get encryptionCert(): string|undefined;
get encryptionCerts(): string[];
get identifierFormat(): string|undefined;
get identityProviderUrl(): string|undefined;
get logoutUrl(): string|undefined;
get signingCert(): string|undefined;
get signingCerts(): string[];
}

View File

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

View File

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