mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #17611 from overleaf/dp-unlink-sso-script
Add script to unlink a third party identifier GitOrigin-RevId: ded0672121fdf8c6cf30f94580f4491af9321dd7
This commit is contained in:
parent
362a947c5a
commit
6fef715316
3 changed files with 93 additions and 0 deletions
|
@ -147,6 +147,7 @@ function unlink(userId, providerId, auditLog, callback) {
|
|||
auditLog.initiatorId,
|
||||
auditLog.ipAddress,
|
||||
{
|
||||
...(auditLog.extraInfo || {}),
|
||||
providerId,
|
||||
},
|
||||
error => {
|
||||
|
|
|
@ -12,6 +12,7 @@ function _canHaveNoInitiatorId(operation, info) {
|
|||
if (operation === 'reset-password') return true
|
||||
if (operation === 'unlink-sso' && info.providerId === 'collabratec')
|
||||
return true
|
||||
if (operation === 'unlink-sso' && info.script === true) return true
|
||||
if (operation === 'unlink-institution-sso-not-migrated') return true
|
||||
if (operation === 'remove-email' && info.script) return true
|
||||
if (operation === 'join-group-subscription') return true
|
||||
|
|
91
services/web/scripts/unlink_third_party_id.js
Normal file
91
services/web/scripts/unlink_third_party_id.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
const { waitForDb } = require('../app/src/infrastructure/mongodb')
|
||||
const minimist = require('minimist')
|
||||
const ThirdPartyIdentityManager = require('../app/src/Features/User/ThirdPartyIdentityManager')
|
||||
const UserGetter = require('../app/src/Features/User/UserGetter')
|
||||
|
||||
/**
|
||||
* This script is used to remove a linked third party identity from a user account.
|
||||
*
|
||||
* Parameters:
|
||||
* --providerId: the third party identity provider (e.g. google, collabratec)
|
||||
* --userId: the id of the user
|
||||
* --commit: if present, the script will commit the changes to the database.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* - dry run:
|
||||
* node scripts/unlink_third_party_id.js --providerId=google --userId=${SOME_USER_ID}
|
||||
* - commit:
|
||||
* node scripts/unlink_third_party_id.js --providerId=google --userId=${SOME_USER_ID} --commit
|
||||
*/
|
||||
|
||||
let COMMIT = false
|
||||
let PROVIDER_ID
|
||||
let USER_ID
|
||||
|
||||
const setup = () => {
|
||||
const argv = minimist(process.argv.slice(2))
|
||||
COMMIT = argv.commit !== undefined
|
||||
PROVIDER_ID = argv.providerId
|
||||
USER_ID = argv.userId
|
||||
if (!COMMIT) {
|
||||
console.warn('Doing dry run. Add --commit to commit changes')
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
if (!PROVIDER_ID) {
|
||||
throw new Error('No --providerId argument provided')
|
||||
}
|
||||
|
||||
if (!USER_ID) {
|
||||
throw new Error('No --userId argument provided')
|
||||
}
|
||||
|
||||
await waitForDb()
|
||||
|
||||
const auditLog = {
|
||||
initiatorId: undefined,
|
||||
ipAddress: '0.0.0.0',
|
||||
extraInfo: {
|
||||
script: true,
|
||||
},
|
||||
}
|
||||
|
||||
const user = await UserGetter.promises.getUser(USER_ID, {
|
||||
thirdPartyIdentifiers: 1,
|
||||
})
|
||||
|
||||
console.log(
|
||||
`Existing thirdPartyIdentifiers: ${JSON.stringify(
|
||||
user.thirdPartyIdentifiers
|
||||
)}`
|
||||
)
|
||||
|
||||
console.log(`Removing third party identifier for provider: ${PROVIDER_ID}`)
|
||||
|
||||
if (COMMIT) {
|
||||
const updatedUser = await ThirdPartyIdentityManager.promises.unlink(
|
||||
USER_ID,
|
||||
PROVIDER_ID,
|
||||
auditLog
|
||||
)
|
||||
|
||||
console.log(
|
||||
`Remaining thirdPartyIdentifiers: ${JSON.stringify(
|
||||
updatedUser.thirdPartyIdentifiers
|
||||
)}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
setup()
|
||||
|
||||
main()
|
||||
.then(() => {
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
Loading…
Reference in a new issue