overleaf/services/web/app/src/Features/User/SAMLIdentityManager.js

34 lines
870 B
JavaScript
Raw Normal View History

const Errors = require('../Errors/Errors')
const { User } = require('../../models/User')
async function getUser(providerId, externalUserId) {
if (providerId == null || externalUserId == null) {
throw new Error('invalid arguments')
}
try {
const query = SAMLIdentityManager._getUserQuery(providerId, externalUserId)
let user = await User.findOne(query).exec()
if (!user) {
throw new Errors.SAMLUserNotFoundError()
}
return user
} catch (error) {
throw error
}
}
const SAMLIdentityManager = {
_getUserQuery(providerId, externalUserId) {
externalUserId = externalUserId.toString()
providerId = providerId.toString()
const query = {
'samlIdentifiers.externalUserId': externalUserId,
'samlIdentifiers.providerId': providerId
}
return query
},
getUser
}
module.exports = SAMLIdentityManager