From bfcef50db9c1c1d34ea550ea156c52cb327e160e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 28 Aug 2018 10:56:09 +0200 Subject: [PATCH] Fix oauth server module --- package.json | 1 - server/initializers/constants.ts | 2 +- server/lib/oauth-model.ts | 6 +++++- server/models/account/user.ts | 5 ----- yarn.lock | 21 +++++---------------- 5 files changed, 11 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 0455dcb2a..a083cab71 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,6 @@ "morgan": "^1.5.3", "multer": "^1.1.0", "nodemailer": "^4.4.2", - "oauth2-server": "^3.0.0", "parse-torrent": "^6.0.0", "password-generator": "^2.0.2", "pem": "^1.12.3", diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 4111d04ec..7f1b25654 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -14,7 +14,7 @@ let config: IConfig = require('config') // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 255 +const LAST_MIGRATION_VERSION = 260 // --------------------------------------------------------------------------- diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts index f159ad6a9..272e90f3a 100644 --- a/server/lib/oauth-model.ts +++ b/server/lib/oauth-model.ts @@ -23,6 +23,7 @@ function getClient (clientId: string, clientSecret: string) { function getRefreshToken (refreshToken: string) { logger.debug('Getting RefreshToken (refreshToken: ' + refreshToken + ').') + return OAuthTokenModel.getByRefreshTokenAndPopulateClient(refreshToken) } @@ -42,7 +43,10 @@ async function getUser (usernameOrEmail: string, password: string) { async function revokeToken (tokenInfo: TokenInfo) { const token = await OAuthTokenModel.getByRefreshTokenAndPopulateUser(tokenInfo.refreshToken) - if (token) token.destroy() + if (token) { + token.destroy() + .catch(err => logger.error('Cannot destroy token when revoking token.', { err })) + } /* * Thanks to https://github.com/manjeshpv/node-oauth2-server-implementation/blob/master/components/oauth/mongo-models.js diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 178012eae..a88ec244f 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -193,9 +193,6 @@ export class UserModel extends Model { return UserModel.findAndCountAll(query) .then(({ rows, count }) => { - console.log(rows[0]) - console.log(rows[0]['videoQuotaUsed']) - console.log(rows[0].get('videoQuotaUsed')) return { data: rows, total: count @@ -208,8 +205,6 @@ export class UserModel extends Model { .map(k => parseInt(k, 10) as UserRole) .filter(role => hasUserRight(role, right)) - console.log(roles) - const query = { attribute: [ 'email' ], where: { diff --git a/yarn.lock b/yarn.lock index 43d97c127..93ffe3619 100644 --- a/yarn.lock +++ b/yarn.lock @@ -646,7 +646,7 @@ basic-auth@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-1.1.0.tgz#45221ee429f7ee1e5035be3f51533f1cdfd29884" -basic-auth@^2.0.0, basic-auth@~2.0.0: +basic-auth@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-2.0.0.tgz#015db3f353e02e56377755f962742e8981e7bbba" dependencies: @@ -816,7 +816,7 @@ bluebird@^2.10.0: version "2.11.0" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1" -bluebird@^3.0.5, bluebird@^3.3.4, bluebird@^3.4.6, bluebird@^3.4.7, bluebird@^3.5.0, bluebird@^3.5.1: +bluebird@^3.0.5, bluebird@^3.3.4, bluebird@^3.4.6, bluebird@^3.4.7, bluebird@^3.5.0: version "3.5.1" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9" @@ -5154,17 +5154,6 @@ oauth2-server@3.0.0: statuses "1.3.1" type-is "1.6.15" -oauth2-server@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/oauth2-server/-/oauth2-server-3.0.1.tgz#8fdb7eb78f107832f75c554cb42e59a3f37e41ea" - dependencies: - basic-auth "^2.0.0" - bluebird "^3.5.1" - lodash "^4.17.10" - promisify-any "^2.0.1" - statuses "^1.5.0" - type-is "^1.6.16" - object-assign@4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.0.tgz#7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0" @@ -5703,7 +5692,7 @@ promise@^7.1.1: dependencies: asap "~2.0.3" -promisify-any@2.0.1, promisify-any@^2.0.1: +promisify-any@2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/promisify-any/-/promisify-any-2.0.1.tgz#403e00a8813f175242ab50fe33a69f8eece47305" dependencies: @@ -6849,7 +6838,7 @@ static-extend@^0.1.1: define-property "^0.2.5" object-copy "^0.1.0" -statuses@1, "statuses@>= 1.3.1 < 2", "statuses@>= 1.4.0 < 2", statuses@^1.5.0: +statuses@1, "statuses@>= 1.3.1 < 2", "statuses@>= 1.4.0 < 2": version "1.5.0" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" @@ -7439,7 +7428,7 @@ type-is@1.6.15: media-typer "0.3.0" mime-types "~2.1.15" -type-is@^1.6.16, type-is@^1.6.4, type-is@~1.6.15, type-is@~1.6.16, type-is@~1.6.6: +type-is@^1.6.4, type-is@~1.6.15, type-is@~1.6.16, type-is@~1.6.6: version "1.6.16" resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.16.tgz#f89ce341541c672b25ee7ae3c73dee3b2be50194" dependencies: -- 2.25.1