From fc72468d0a8edf0ef53227ef65074a241d101603 Mon Sep 17 00:00:00 2001 From: Daphne Date: Fri, 25 Oct 2019 22:28:56 +0200 Subject: [PATCH] Feature/types passport oauth2 refresh (#39425) * added typings for passport-oauth2-refresh library * fix linting issues with passport-oauth2-refresh --- types/passport-oauth2-refresh/index.d.ts | 13 +++++++++++ .../passport-oauth2-refresh-tests.ts | 20 ++++++++++++++++ types/passport-oauth2-refresh/tsconfig.json | 23 +++++++++++++++++++ types/passport-oauth2-refresh/tslint.json | 1 + 4 files changed, 57 insertions(+) create mode 100644 types/passport-oauth2-refresh/index.d.ts create mode 100644 types/passport-oauth2-refresh/passport-oauth2-refresh-tests.ts create mode 100644 types/passport-oauth2-refresh/tsconfig.json create mode 100644 types/passport-oauth2-refresh/tslint.json diff --git a/types/passport-oauth2-refresh/index.d.ts b/types/passport-oauth2-refresh/index.d.ts new file mode 100644 index 0000000000..cdbcf2f714 --- /dev/null +++ b/types/passport-oauth2-refresh/index.d.ts @@ -0,0 +1,13 @@ +// Type definitions for passport-oauth2-refresh 1.1 +// Project: https://github.com/fiznool/passport-oauth2-refresh#readme +// Definitions by: Daphne Smit +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { Strategy } from 'passport-oauth2'; + +export function use(name: string | Strategy, strategy?: Strategy): void; + +export function has(name: string): boolean; + +export function requestNewAccessToken(name: string, refreshToken: string, params: any, done: () => any): any; diff --git a/types/passport-oauth2-refresh/passport-oauth2-refresh-tests.ts b/types/passport-oauth2-refresh/passport-oauth2-refresh-tests.ts new file mode 100644 index 0000000000..7295948c6c --- /dev/null +++ b/types/passport-oauth2-refresh/passport-oauth2-refresh-tests.ts @@ -0,0 +1,20 @@ +import { Strategy as OAuth2Strategy, StrategyOptions, VerifyCallback } from 'passport-oauth2'; +import { use, requestNewAccessToken } from 'passport-oauth2-refresh'; + +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' +}; + +function verifyFunction1(_accessToken: string, _refreshToken: string, _profile: any, verifyCallback: VerifyCallback) { + verifyCallback(new Error('unimplemented')); +} + +const strategy1: OAuth2Strategy = new OAuth2Strategy(strategyOptions1, verifyFunction1); + +use('strategy1', strategy1); + +requestNewAccessToken('strategy1', 'exampleRefreshToken', {}, () => {}); diff --git a/types/passport-oauth2-refresh/tsconfig.json b/types/passport-oauth2-refresh/tsconfig.json new file mode 100644 index 0000000000..993bc681dd --- /dev/null +++ b/types/passport-oauth2-refresh/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-oauth2-refresh-tests.ts" + ] +} diff --git a/types/passport-oauth2-refresh/tslint.json b/types/passport-oauth2-refresh/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/passport-oauth2-refresh/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }