diff --git a/types/oauth-shim/index.d.ts b/types/oauth-shim/index.d.ts new file mode 100644 index 0000000000..a5016aed9f --- /dev/null +++ b/types/oauth-shim/index.d.ts @@ -0,0 +1,47 @@ +// Type definitions for oauth-shim 1.1 +// Project: https://github.com/MrSwitch/node-oauth-shim +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import * as express from "express"; + +export = oauthShim; + +declare const oauthShim: oauthShim.Handler; + +declare namespace oauthShim { + interface Handler extends express.RequestHandler { + interpret: express.RequestHandler; + proxy: express.RequestHandler; + redirect: express.RequestHandler; + unhandled: express.RequestHandler; + + credentials: { + get(query: any, cb: (success: false | object) => void): void; + }; + + init(configs: Config[]): void; + } + + interface Request extends express.Request { + oauthshim?: { + options?: { + [key: string]: any; + path?: string; + }; + redirect?: string; + data?: { + [key: string]: any; + access_token?: string; + }; + }; + } + + interface Config { + client_id: string; + client_secret: string; + grant_url: string; + domain: string; + } +} diff --git a/types/oauth-shim/oauth-shim-tests.ts b/types/oauth-shim/oauth-shim-tests.ts new file mode 100644 index 0000000000..2a287f8bda --- /dev/null +++ b/types/oauth-shim/oauth-shim-tests.ts @@ -0,0 +1,51 @@ +import oauthshim = require("oauth-shim"); +import express = require("express"); + +const app = express(); +app.listen(3000); +app.all("/oauthproxy", oauthshim); + +oauthshim.init([ + { + client_id: "12345", + client_secret: "secret678910", + grant_url: "https://linkedIn.com", + domain: "test.com, example.com/redirect", + }, +]); + +function customHandler(req: oauthshim.Request, res: express.Response, next: express.NextFunction) { + if ( + req.oauthshim && + req.oauthshim.redirect && + req.oauthshim.data && + req.oauthshim.data.access_token && + req.oauthshim.options && + !req.oauthshim.options.path + ) {} + + next(); +} + +app.all( + "/oauthproxy", + oauthshim.interpret, + customHandler, + oauthshim.proxy, + oauthshim.redirect, + oauthshim.unhandled +); + +oauthshim.credentials.get = (query, callback) => { + if (query.client_id === "12345") { + callback({ + client_secret: "secret678910", + }); + } else if (query.client_id === "abcde") { + callback({ + client_secret: "secret123456", + }); + } else { + callback(false); + } +}; diff --git a/types/oauth-shim/tsconfig.json b/types/oauth-shim/tsconfig.json new file mode 100644 index 0000000000..3c7fc0ad5a --- /dev/null +++ b/types/oauth-shim/tsconfig.json @@ -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", + "oauth-shim-tests.ts" + ] +} diff --git a/types/oauth-shim/tslint.json b/types/oauth-shim/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/oauth-shim/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }