diff --git a/types/passport-saml-metadata/index.d.ts b/types/passport-saml-metadata/index.d.ts new file mode 100644 index 0000000000..9ba79a0c32 --- /dev/null +++ b/types/passport-saml-metadata/index.d.ts @@ -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 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.8 + +export * from "./src"; diff --git a/types/passport-saml-metadata/passport-saml-metadata-tests.ts b/types/passport-saml-metadata/passport-saml-metadata-tests.ts new file mode 100644 index 0000000000..50795305e2 --- /dev/null +++ b/types/passport-saml-metadata/passport-saml-metadata-tests.ts @@ -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 diff --git a/types/passport-saml-metadata/src/fetch.d.ts b/types/passport-saml-metadata/src/fetch.d.ts new file mode 100644 index 0000000000..9070ddf88c --- /dev/null +++ b/types/passport-saml-metadata/src/fetch.d.ts @@ -0,0 +1,12 @@ +export interface FetchAxiosConfig { + backupStore: Map; + responseType: string; + timeout: number; +} + +export type FetchConfig = { + client?: {get(url: string, params?: Partial): Promise<{data: string}>}; + url: string; +} & Partial; + +export function fetch(config: FetchConfig): Promise; diff --git a/types/passport-saml-metadata/src/index.d.ts b/types/passport-saml-metadata/src/index.d.ts new file mode 100644 index 0000000000..29669081c1 --- /dev/null +++ b/types/passport-saml-metadata/src/index.d.ts @@ -0,0 +1,7 @@ +import { FetchConfig } from "./fetch"; +import { MetadataReader } from "./reader"; + +export function fetch(config: FetchConfig): Promise; +export { metadata } from "./metadata"; +export { claimsToCamelCase, toPassportConfig } from "./passport"; +export { MetadataReader } from "./reader"; diff --git a/types/passport-saml-metadata/src/metadata.d.ts b/types/passport-saml-metadata/src/metadata.d.ts new file mode 100644 index 0000000000..e90189c288 --- /dev/null +++ b/types/passport-saml-metadata/src/metadata.d.ts @@ -0,0 +1,3 @@ +import { SamlConfig } from "passport-saml"; + +export function metadata(config: SamlConfig): (() => void); diff --git a/types/passport-saml-metadata/src/passport.d.ts b/types/passport-saml-metadata/src/passport.d.ts new file mode 100644 index 0000000000..cd0601ecb3 --- /dev/null +++ b/types/passport-saml-metadata/src/passport.d.ts @@ -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; diff --git a/types/passport-saml-metadata/src/reader.d.ts b/types/passport-saml-metadata/src/reader.d.ts new file mode 100644 index 0000000000..2dae4731d8 --- /dev/null +++ b/types/passport-saml-metadata/src/reader.d.ts @@ -0,0 +1,15 @@ +export interface MetadataConstructorOptions { + authnRequestBinding: string; + throwExceptions: boolean; +} +export class MetadataReader { + constructor(metadata: string, options?: Partial); + 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[]; +} diff --git a/types/passport-saml-metadata/tsconfig.json b/types/passport-saml-metadata/tsconfig.json new file mode 100644 index 0000000000..41a7cf17d1 --- /dev/null +++ b/types/passport-saml-metadata/tsconfig.json @@ -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" + ] +} diff --git a/types/passport-saml-metadata/tslint.json b/types/passport-saml-metadata/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/passport-saml-metadata/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }