From a80f469c217392caf2b4434f42d8c173a1ba87e8 Mon Sep 17 00:00:00 2001 From: Thomas Heymann Date: Fri, 22 May 2020 09:00:09 +0100 Subject: [PATCH] Upgrade dependencies --- index.js | 8 ++++---- package.json | 4 ++-- test.js | 12 ++++++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 7a990af..44dc38b 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ const fp = require('fastify-plugin') const oauth2Module = require('simple-oauth2') const promisify = require('util').promisify || require('es6-promisify').promisify +const callbackify = require('util').callbackify function defaultGenerateStateFunction () { return defaultState @@ -73,10 +74,10 @@ const oauthPlugin = fp(function (fastify, options, next) { } const cbk = function (o, code, callback) { - return o.oauth2.authorizationCode.getToken({ + return callbackify(o.oauth2.authorizationCode.getToken.bind(o.oauth2.authorizationCode, { code: code, redirect_uri: callbackUri - }, callback) + }))(callback) } function getAccessTokenFromAuthorizationCodeFlowCallbacked (request, callback) { @@ -102,7 +103,7 @@ const oauthPlugin = fp(function (fastify, options, next) { function getNewAccessTokenUsingRefreshTokenCallbacked (refreshToken, params, callback) { const accessToken = fastify[name].oauth2.accessToken.create({ refresh_token: refreshToken }) - accessToken.refresh(params, callback) + callbackify(accessToken.refresh.bind(accessToken, params))(callback) } const getNewAccessTokenUsingRefreshTokenPromisified = promisify(getNewAccessTokenUsingRefreshTokenCallbacked) @@ -112,7 +113,6 @@ const oauthPlugin = fp(function (fastify, options, next) { } getNewAccessTokenUsingRefreshTokenCallbacked(refreshToken, params, callback) } - const oauth2 = oauth2Module.create(credentials) if (startRedirectPath) { diff --git a/package.json b/package.json index e3f2b3c..ed33664 100644 --- a/package.json +++ b/package.json @@ -26,12 +26,12 @@ "homepage": "https://github.com/fastify/fastify-oauth2#readme", "devDependencies": { "fastify": "^3.0.0-rc.1", - "nock": "^9.0.0", + "nock": "^12.0.3", "pre-commit": "^1.2.2", "simple-get": "^3.0.2", "snazzy": "^8.0.0", "standard": "^14.3.3", - "tap": "^12.0.0", + "tap": "^14.10.7", "tsd": "^0.11.0" }, "dependencies": { diff --git a/test.js b/test.js index ab89445..e2a3340 100644 --- a/test.js +++ b/test.js @@ -39,9 +39,17 @@ function makeRequests (t, fastify) { } const githubScope = nock('https://github.com') - .post('/login/oauth/access_token', 'code=my-code&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcallback&grant_type=authorization_code&client_id=my-client-id&client_secret=my-secret') + .post('/login/oauth/access_token', 'grant_type=authorization_code&code=my-code&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcallback', { + reqheaders: { + authorization: 'Basic bXktY2xpZW50LWlkOm15LXNlY3JldA==' + } + }) .reply(200, RESPONSE_BODY) - .post('/login/oauth/access_token', 'grant_type=refresh_token&refresh_token=my-refresh-token&client_id=my-client-id&client_secret=my-secret') + .post('/login/oauth/access_token', 'grant_type=refresh_token&refresh_token=my-refresh-token', { + reqheaders: { + authorization: 'Basic bXktY2xpZW50LWlkOm15LXNlY3JldA==' + } + }) .reply(200, RESPONSE_BODY_REFRESHED) fastify.inject({