From e6e6da78381e651c7da11c3d856cdafdb267b760 Mon Sep 17 00:00:00 2001 From: Eduardo Aparicio Cardenes Date: Mon, 15 Oct 2018 19:18:54 +0200 Subject: [PATCH] Fix callback type in OAuth type definition (#29542) Clearly we can see in the OAuth2 repository that the callback type is a function that is call on [_executeRequest](https://github.com/ciaranj/node-oauth/blob/master/lib/oauth2.js) coming from the [get](https://github.com/ciaranj/node-oauth/blob/master/lib/oauth2.js#L219) callback defition If you follow the trace of _executeRequest and _request function types you will see that the callback function type is wrong --- types/oauth/index.d.ts | 7 ++++--- types/passport-oauth2/index.d.ts | 1 + types/passport-oauth2/passport-oauth2-tests.ts | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/types/oauth/index.d.ts b/types/oauth/index.d.ts index 21b74369e9..9f747e8b84 100644 --- a/types/oauth/index.d.ts +++ b/types/oauth/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for oauth 0.9 // Project: https://github.com/ciaranj/node-oauth#readme // Definitions by: nonAlgebraic +// Eduardo AC // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -25,8 +26,8 @@ export type oauth2tokenCallback = ( export type dataCallback = ( err: {statusCode: number, data?: any}, - result: string | Buffer, - response: IncomingMessage + result?: string | Buffer, + response?: IncomingMessage ) => any; export class OAuth { @@ -285,7 +286,7 @@ export class OAuth2 { get(url: string, access_token: string, - callback: string + callback: dataCallback ): void; protected _getAccessTokenUrl(): string; diff --git a/types/passport-oauth2/index.d.ts b/types/passport-oauth2/index.d.ts index 7d7f3de21d..d985852bd6 100644 --- a/types/passport-oauth2/index.d.ts +++ b/types/passport-oauth2/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/jaredhanson/passport-oauth2#readme // Definitions by: Pasi Eronen // Wang Zishi +// Eduardo AC // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 diff --git a/types/passport-oauth2/passport-oauth2-tests.ts b/types/passport-oauth2/passport-oauth2-tests.ts index 6a5d09ef27..864b2cb9d6 100644 --- a/types/passport-oauth2/passport-oauth2-tests.ts +++ b/types/passport-oauth2/passport-oauth2-tests.ts @@ -51,6 +51,8 @@ const err3 = new InternalOAuthError('Hello', {}); class MyStrategy extends OAuth2Strategy { useProtectedProperty() { - this._oauth2.get('http://www.example.com/profile', 'token', 'http://www.example.com/callback'); + 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); } }