add types for oauth-shim (#30632)

This commit is contained in:
Dimitri Benin
2018-11-18 11:15:19 -08:00
committed by Pranav Senthilnathan
parent 4b2af06acd
commit 05c33e7019
4 changed files with 122 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
// Type definitions for oauth-shim 1.1
// Project: https://github.com/MrSwitch/node-oauth-shim
// Definitions by: BendingBender <https://github.com/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;
}
}
+51
View File
@@ -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);
}
};
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }