feat: Add ability to unlink SSO from user

This commit is contained in:
Maksim Eltyshev
2026-01-26 21:18:32 +01:00
parent ee917c545c
commit 2b699f77f4
39 changed files with 238 additions and 9 deletions
+7 -1
View File
@@ -123,6 +123,7 @@
* $ref: '#/components/responses/Conflict'
*/
const { is } = require('../../../utils/validators');
const { idInput } = require('../../../utils/inputs');
const Errors = {
@@ -200,6 +201,10 @@ module.exports = {
type: 'string',
isIn: Object.values(User.ProjectOrders),
},
isSsoUser: {
type: 'boolean',
custom: is(false),
},
isDeactivated: {
type: 'boolean',
},
@@ -224,7 +229,7 @@ module.exports = {
if (inputs.id === currentUser.id) {
availableInputKeys.push(...User.PERSONAL_FIELD_NAMES);
} else if (currentUser.role === User.Roles.ADMIN) {
availableInputKeys.push('role', 'isDeactivated');
availableInputKeys.push('role', 'isSsoUser', 'isDeactivated');
} else {
throw Errors.USER_NOT_FOUND; // Forbidden
}
@@ -274,6 +279,7 @@ module.exports = {
'defaultEditorMode',
'defaultHomeView',
'defaultProjectsOrder',
'isSsoUser',
'isDeactivated',
]),
};
+19 -8
View File
@@ -15,6 +15,7 @@ const openidClient = require('openid-client');
module.exports = function defineOidcHook(sails) {
let client = null;
let clientInitPromise = null;
return {
/**
@@ -28,9 +29,20 @@ module.exports = function defineOidcHook(sails) {
sails.log.info('Initializing custom hook (`oidc`)');
},
// TODO: wait for initialization if called more than once
async getClient() {
if (this.isEnabled() && !this.isActive()) {
if (!this.isEnabled()) {
return null;
}
if (client) {
return client;
}
if (clientInitPromise) {
return clientInitPromise;
}
clientInitPromise = (async () => {
sails.log.info('Initializing OIDC client');
let issuer;
@@ -38,6 +50,8 @@ module.exports = function defineOidcHook(sails) {
issuer = await openidClient.Issuer.discover(sails.config.custom.oidcIssuer);
} catch (error) {
sails.log.warn(`Error while initializing OIDC client: ${error}`);
clientInitPromise = null;
return null;
}
@@ -54,9 +68,10 @@ module.exports = function defineOidcHook(sails) {
}
client = new issuer.Client(metadata);
}
return client;
})();
return client;
return clientInitPromise;
},
async getBootstrap() {
@@ -84,9 +99,5 @@ module.exports = function defineOidcHook(sails) {
isEnabled() {
return !!sails.config.custom.oidcIssuer;
},
isActive() {
return client !== null;
},
};
};
+3
View File
@@ -13,6 +13,8 @@ const ID_REGEX = /^[1-9][0-9]*$/;
const IDS_WITH_COMMA_REGEX = /^[1-9][0-9]*(,[1-9][0-9]*)*$/;
const USERNAME_REGEX = /^[a-zA-Z0-9]+((_|\.)?[a-zA-Z0-9])*$/;
const is = (defaultValue) => (value) => value === defaultValue;
const isUrl = (value) =>
validator.isURL(value, {
protocols: ['http', 'https'],
@@ -61,6 +63,7 @@ module.exports = {
IDS_WITH_COMMA_REGEX,
USERNAME_REGEX,
is,
isUrl,
isIdInRange,
isIdsWithCommaInRange,