From ff503e74dd923e53cf48c6989eda5cc6a3b543d0 Mon Sep 17 00:00:00 2001 From: Ivan Fernandes Date: Sun, 2 Dec 2018 01:38:59 -0200 Subject: [PATCH 1/4] passport-bnet type definitions --- types/passport-bnet/index.d.ts | 42 ++++++++++++++ types/passport-bnet/passport-bnet-tests.ts | 65 ++++++++++++++++++++++ types/passport-bnet/tsconfig.json | 23 ++++++++ types/passport-bnet/tslint.json | 1 + 4 files changed, 131 insertions(+) create mode 100644 types/passport-bnet/index.d.ts create mode 100644 types/passport-bnet/passport-bnet-tests.ts create mode 100644 types/passport-bnet/tsconfig.json create mode 100644 types/passport-bnet/tslint.json diff --git a/types/passport-bnet/index.d.ts b/types/passport-bnet/index.d.ts new file mode 100644 index 0000000000..ef6f977830 --- /dev/null +++ b/types/passport-bnet/index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for passport-bnet 2.0.0 +// Project: https://github.com/Blizzard/passport-bnet#readme +// Definitions by: Ivan Fernandes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Strategy as OAuth2Strategy, VerifyFunction, VerifyFunctionWithRequest } from 'passport-oauth2'; + +declare class BnetStrategy extends OAuth2Strategy { + constructor(options: BnetStrategy.StrategyOptions, verify: VerifyFunction); + constructor(options: BnetStrategy.StrategyOptionsWithRequest, verify: VerifyFunctionWithRequest); +} + +declare namespace BnetStrategy { + + interface _BaseBnetOptions { + region?: string; + + scopeSeparator?: string; + customHeaders?: object; + authorizationURL?: string; + tokenURL?: string; + scope?: string; + clientID: string; + clientSecret: string; + callbackURL?: string; + } + + interface StrategyOptions extends _BaseBnetOptions { + passReqToCallback?: false; + } + + interface StrategyOptionsWithRequest extends _BaseBnetOptions { + passReqToCallback: true; + } + + function getHost(region: string): string; + + type Strategy = BnetStrategy; + const Strategy: typeof BnetStrategy; +} + +export = BnetStrategy \ No newline at end of file diff --git a/types/passport-bnet/passport-bnet-tests.ts b/types/passport-bnet/passport-bnet-tests.ts new file mode 100644 index 0000000000..86f3090c88 --- /dev/null +++ b/types/passport-bnet/passport-bnet-tests.ts @@ -0,0 +1,65 @@ +//Based on passport-oauth2/passport-oauth2-tests.ts + +import BnetStrategy = require("passport-bnet"); +import { Strategy, StrategyOptions, StrategyOptionsWithRequest } from "passport-bnet"; +import { Strategy as OAuth2Strategy } from "passport-oauth2"; +import { VerifyCallback } from "passport-oauth2"; +import { Request } from "express"; + +const strategyOptions1: StrategyOptions = { + authorizationURL: 'http://www.example.com/auth', + callbackURL: 'http://www.example.com/callback', + clientID: 'dummy', + clientSecret: 'secret', + tokenURL: 'http://www.example.com/token', + region: 'us', + scope: "email", + scopeSeparator: ' ', + customHeaders: {} +} + +function verifyFunction1(_accessToken: string, _refreshToken: string, _profile: any, verifyCallback: VerifyCallback) { + verifyCallback(new Error('unimplemented')); +} + +function verifyFunction2(_accessToken: string, _refreshToken: string, _results: any, _profile: any, verifyCallback: VerifyCallback) { + verifyCallback(new Error('unimplemented')); +} + +const strategy1: BnetStrategy = new BnetStrategy(strategyOptions1, verifyFunction1); + +const strategy2: Strategy = new BnetStrategy(strategyOptions1, verifyFunction2); + +function verifyFunction3(_req: Request, _accessToken: string, _refreshToken: string, _profile: any, verifyCallback: VerifyCallback) { + verifyCallback(undefined, { userid: '1' }); +} + +function verifyFunction4(_req: Request, _accessToken: string, _refreshToken: string, _results: any, _profile: any, verifyCallback: VerifyCallback) { + verifyCallback(undefined, { userid: '1' }); +} + +const strategyOptions2: StrategyOptionsWithRequest = { + authorizationURL: 'http://www.example.com/auth', + callbackURL: 'http://www.example.com/callback', + clientID: 'dummy', + clientSecret: 'secret', + tokenURL: 'http://www.example.com/token', + region: 'us', + scope: "email", + scopeSeparator: ' ', + customHeaders: {}, + passReqToCallback: true +}; + +const strategy3: OAuth2Strategy = new BnetStrategy +(strategyOptions2, verifyFunction3); + +const strategy4: Strategy = new Strategy(strategyOptions2, verifyFunction4); + +class MyStrategy extends BnetStrategy { + useProtectedProperty() { + this._oauth2.get('http://www.example.com/profile', 'token', err => err.statusCode); + this._oauth2.get('http://www.example.com/profile', 'token', (err, result) => result); + this._oauth2.get('http://www.example.com/profile', 'token', (err, result, response) => response); + } +} \ No newline at end of file diff --git a/types/passport-bnet/tsconfig.json b/types/passport-bnet/tsconfig.json new file mode 100644 index 0000000000..28da7a7a65 --- /dev/null +++ b/types/passport-bnet/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", + "passport-bnet-tests.ts" + ] +} \ No newline at end of file diff --git a/types/passport-bnet/tslint.json b/types/passport-bnet/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/passport-bnet/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 374b24ef8732e7907faef7bb13b4326191d1747d Mon Sep 17 00:00:00 2001 From: Ivan Fernandes Date: Sun, 2 Dec 2018 02:03:00 -0200 Subject: [PATCH 2/4] adding typescript version --- types/passport-bnet/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/passport-bnet/index.d.ts b/types/passport-bnet/index.d.ts index ef6f977830..1b28ee21ad 100644 --- a/types/passport-bnet/index.d.ts +++ b/types/passport-bnet/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/Blizzard/passport-bnet#readme // Definitions by: Ivan Fernandes // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 import { Strategy as OAuth2Strategy, VerifyFunction, VerifyFunctionWithRequest } from 'passport-oauth2'; From 55dc8ebd80d0386841468e2c515aba766fba5da3 Mon Sep 17 00:00:00 2001 From: Ivan Fernandes Date: Sun, 2 Dec 2018 02:10:27 -0200 Subject: [PATCH 3/4] fomatting --- types/passport-bnet/index.d.ts | 7 +++---- types/passport-bnet/passport-bnet-tests.ts | 9 ++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/types/passport-bnet/index.d.ts b/types/passport-bnet/index.d.ts index 1b28ee21ad..e5493a8d3c 100644 --- a/types/passport-bnet/index.d.ts +++ b/types/passport-bnet/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for passport-bnet 2.0.0 +// Type definitions for passport-bnet 2.0. // Project: https://github.com/Blizzard/passport-bnet#readme // Definitions by: Ivan Fernandes // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -12,7 +12,6 @@ declare class BnetStrategy extends OAuth2Strategy { } declare namespace BnetStrategy { - interface _BaseBnetOptions { region?: string; @@ -20,7 +19,7 @@ declare namespace BnetStrategy { customHeaders?: object; authorizationURL?: string; tokenURL?: string; - scope?: string; + scope?: string; clientID: string; clientSecret: string; callbackURL?: string; @@ -40,4 +39,4 @@ declare namespace BnetStrategy { const Strategy: typeof BnetStrategy; } -export = BnetStrategy \ No newline at end of file +export = BnetStrategy; diff --git a/types/passport-bnet/passport-bnet-tests.ts b/types/passport-bnet/passport-bnet-tests.ts index 86f3090c88..06c0ffccec 100644 --- a/types/passport-bnet/passport-bnet-tests.ts +++ b/types/passport-bnet/passport-bnet-tests.ts @@ -1,9 +1,8 @@ -//Based on passport-oauth2/passport-oauth2-tests.ts +// Based on passport-oauth2/passport-oauth2-tests.ts import BnetStrategy = require("passport-bnet"); import { Strategy, StrategyOptions, StrategyOptionsWithRequest } from "passport-bnet"; -import { Strategy as OAuth2Strategy } from "passport-oauth2"; -import { VerifyCallback } from "passport-oauth2"; +import { Strategy as OAuth2Strategy, VerifyCallback } from "passport-oauth2"; import { Request } from "express"; const strategyOptions1: StrategyOptions = { @@ -16,7 +15,7 @@ const strategyOptions1: StrategyOptions = { scope: "email", scopeSeparator: ' ', customHeaders: {} -} +}; function verifyFunction1(_accessToken: string, _refreshToken: string, _profile: any, verifyCallback: VerifyCallback) { verifyCallback(new Error('unimplemented')); @@ -62,4 +61,4 @@ class MyStrategy extends BnetStrategy { this._oauth2.get('http://www.example.com/profile', 'token', (err, result) => result); this._oauth2.get('http://www.example.com/profile', 'token', (err, result, response) => response); } -} \ No newline at end of file +} From 47fa3e69a48443e99093497e234cd5fb4159761d Mon Sep 17 00:00:00 2001 From: Ivan Fernandes Date: Sun, 2 Dec 2018 02:12:46 -0200 Subject: [PATCH 4/4] fixing version notation --- types/passport-bnet/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/passport-bnet/index.d.ts b/types/passport-bnet/index.d.ts index e5493a8d3c..86255c782d 100644 --- a/types/passport-bnet/index.d.ts +++ b/types/passport-bnet/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for passport-bnet 2.0. +// Type definitions for passport-bnet 2.0 // Project: https://github.com/Blizzard/passport-bnet#readme // Definitions by: Ivan Fernandes // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped