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
+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;
},
};
};