mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-29 12:01:32 +02:00
remove collabratec v1 deps, and user stubs for oauth
GitOrigin-RevId: c4bc497a07658eb580b0bfdb011fea32ea1657e1
This commit is contained in:
committed by
sharelatex
parent
aec0ea5b08
commit
fb55063c2f
@@ -308,14 +308,8 @@ const AuthenticationController = (module.exports = {
|
||||
return doRequest
|
||||
},
|
||||
|
||||
// access tokens might be associated with user stubs if the user is
|
||||
// not yet migrated to v2. if api can work with user stubs then set
|
||||
// allowUserStub true when adding middleware to route.
|
||||
requireOauth(allowUserStub) {
|
||||
requireOauth() {
|
||||
// require this here because module may not be included in some versions
|
||||
if (allowUserStub == null) {
|
||||
allowUserStub = false
|
||||
}
|
||||
const Oauth2Server = require('../../../../modules/oauth2-server/app/src/Oauth2Server')
|
||||
return function(req, res, next) {
|
||||
if (next == null) {
|
||||
@@ -340,9 +334,6 @@ const AuthenticationController = (module.exports = {
|
||||
.status(err.code)
|
||||
.json({ error: err.name, error_description: err.message })
|
||||
}
|
||||
if (token.user.constructor.modelName === 'UserStub' && !allowUserStub) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
req.oauth = { access_token: token.accessToken }
|
||||
req.oauth_token = token
|
||||
req.oauth_user = token.user
|
||||
|
||||
@@ -1,23 +1,9 @@
|
||||
/* eslint-disable
|
||||
camelcase,
|
||||
max-len,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
let ThirdPartyIdentityManager
|
||||
const Errors = require('../Errors/Errors')
|
||||
const { User } = require('../../models/User')
|
||||
const { UserStub } = require('../../models/UserStub')
|
||||
const UserUpdater = require('./UserUpdater')
|
||||
const _ = require('lodash')
|
||||
|
||||
module.exports = ThirdPartyIdentityManager = {
|
||||
const ThirdPartyIdentityManager = (module.exports = {
|
||||
getUser(providerId, externalUserId, callback) {
|
||||
if (providerId == null || externalUserId == null) {
|
||||
return callback(new Error('invalid arguments'))
|
||||
@@ -26,85 +12,40 @@ module.exports = ThirdPartyIdentityManager = {
|
||||
providerId,
|
||||
externalUserId
|
||||
)
|
||||
return User.findOne(query, function(err, user) {
|
||||
User.findOne(query, function(err, user) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
if (!user) {
|
||||
return callback(new Errors.ThirdPartyUserNotFoundError())
|
||||
}
|
||||
return callback(null, user)
|
||||
callback(null, user)
|
||||
})
|
||||
},
|
||||
|
||||
login(providerId, externalUserId, externalData, callback) {
|
||||
return ThirdPartyIdentityManager.getUser(
|
||||
providerId,
|
||||
externalUserId,
|
||||
function(err, user) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
if (!externalData) {
|
||||
return callback(null, user)
|
||||
}
|
||||
const query = ThirdPartyIdentityManager._getUserQuery(
|
||||
providerId,
|
||||
externalUserId
|
||||
)
|
||||
const update = ThirdPartyIdentityManager._thirdPartyIdentifierUpdate(
|
||||
user,
|
||||
providerId,
|
||||
externalUserId,
|
||||
externalData
|
||||
)
|
||||
return User.findOneAndUpdate(query, update, { new: true }, callback)
|
||||
ThirdPartyIdentityManager.getUser(providerId, externalUserId, function(
|
||||
err,
|
||||
user
|
||||
) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
// attempt to login normally but check for user stub if user not found
|
||||
loginUserStub(providerId, externalUserId, externalData, callback) {
|
||||
return ThirdPartyIdentityManager.login(
|
||||
providerId,
|
||||
externalUserId,
|
||||
externalData,
|
||||
function(err, user) {
|
||||
if (err == null) {
|
||||
return callback(null, user)
|
||||
}
|
||||
if (err.name !== 'ThirdPartyUserNotFoundError') {
|
||||
return callback(err)
|
||||
}
|
||||
const query = ThirdPartyIdentityManager._getUserQuery(
|
||||
providerId,
|
||||
externalUserId
|
||||
)
|
||||
return UserStub.findOne(query, function(err, userStub) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
if (!userStub) {
|
||||
return callback(new Errors.ThirdPartyUserNotFoundError())
|
||||
}
|
||||
if (!externalData) {
|
||||
return callback(null, userStub)
|
||||
}
|
||||
const update = ThirdPartyIdentityManager._thirdPartyIdentifierUpdate(
|
||||
userStub,
|
||||
providerId,
|
||||
externalUserId,
|
||||
externalData
|
||||
)
|
||||
return UserStub.findOneAndUpdate(
|
||||
query,
|
||||
update,
|
||||
{ new: true },
|
||||
callback
|
||||
)
|
||||
})
|
||||
if (!externalData) {
|
||||
return callback(null, user)
|
||||
}
|
||||
)
|
||||
const query = ThirdPartyIdentityManager._getUserQuery(
|
||||
providerId,
|
||||
externalUserId
|
||||
)
|
||||
const update = ThirdPartyIdentityManager._thirdPartyIdentifierUpdate(
|
||||
user,
|
||||
providerId,
|
||||
externalUserId,
|
||||
externalData
|
||||
)
|
||||
User.findOneAndUpdate(query, update, { new: true }, callback)
|
||||
})
|
||||
},
|
||||
|
||||
_getUserQuery(providerId, externalUserId) {
|
||||
@@ -135,9 +76,9 @@ module.exports = ThirdPartyIdentityManager = {
|
||||
// but for now we need to register with v1 then call link once that
|
||||
// is complete
|
||||
|
||||
link(user_id, providerId, externalUserId, externalData, callback, retry) {
|
||||
link(userId, providerId, externalUserId, externalData, callback, retry) {
|
||||
const query = {
|
||||
_id: user_id,
|
||||
_id: userId,
|
||||
'thirdPartyIdentifiers.providerId': {
|
||||
$ne: providerId
|
||||
}
|
||||
@@ -152,7 +93,7 @@ module.exports = ThirdPartyIdentityManager = {
|
||||
}
|
||||
}
|
||||
// add new tpi only if an entry for the provider does not exist
|
||||
return UserUpdater.updateUser(query, update, function(err, res) {
|
||||
UserUpdater.updateUser(query, update, function(err, res) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
@@ -164,14 +105,12 @@ module.exports = ThirdPartyIdentityManager = {
|
||||
return callback(new Error('update failed'))
|
||||
}
|
||||
// attempt to clear existing entry then retry
|
||||
return ThirdPartyIdentityManager.unlink(user_id, providerId, function(
|
||||
err
|
||||
) {
|
||||
ThirdPartyIdentityManager.unlink(userId, providerId, function(err) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
return ThirdPartyIdentityManager.link(
|
||||
user_id,
|
||||
ThirdPartyIdentityManager.link(
|
||||
userId,
|
||||
providerId,
|
||||
externalUserId,
|
||||
externalData,
|
||||
@@ -182,7 +121,7 @@ module.exports = ThirdPartyIdentityManager = {
|
||||
})
|
||||
},
|
||||
|
||||
unlink(user_id, providerId, callback) {
|
||||
unlink(userId, providerId, callback) {
|
||||
const update = {
|
||||
$pull: {
|
||||
thirdPartyIdentifiers: {
|
||||
@@ -190,29 +129,6 @@ module.exports = ThirdPartyIdentityManager = {
|
||||
}
|
||||
}
|
||||
}
|
||||
return UserUpdater.updateUser(user_id, update, callback)
|
||||
},
|
||||
|
||||
// attempt to unlink user but unlink user stub if not linked to user
|
||||
unlinkUserStub(user_id, providerId, callback) {
|
||||
return ThirdPartyIdentityManager.unlink(user_id, providerId, function(
|
||||
err,
|
||||
res
|
||||
) {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
if (res.nModified === 1) {
|
||||
return callback(null, res)
|
||||
}
|
||||
const update = {
|
||||
$pull: {
|
||||
thirdPartyIdentifiers: {
|
||||
providerId
|
||||
}
|
||||
}
|
||||
}
|
||||
return UserStub.update({ _id: user_id }, update, callback)
|
||||
})
|
||||
UserUpdater.updateUser(userId, update, callback)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user