Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
79 lines
2.5 KiB
TypeScript
79 lines
2.5 KiB
TypeScript
import type { ServerMethods } from '@rocket.chat/ddp-client';
|
|
import { Users } from '@rocket.chat/models';
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import type { IServiceProviderOptions } from '../../lib/saml/definition/IServiceProviderOptions';
|
|
import { SAMLServiceProvider } from '../../lib/saml/lib/ServiceProvider';
|
|
import { SAMLUtils } from '../../lib/saml/lib/Utils';
|
|
|
|
/**
|
|
* Fetch SAML provider configs for given 'provider'.
|
|
*/
|
|
function getSamlServiceProviderOptions(provider: string): IServiceProviderOptions {
|
|
if (!provider) {
|
|
throw new Meteor.Error('no-saml-provider', 'SAML internal error', {
|
|
method: 'getSamlServiceProviderOptions',
|
|
});
|
|
}
|
|
|
|
const providers = SAMLUtils.serviceProviders;
|
|
|
|
const samlProvider = function (element: IServiceProviderOptions): boolean {
|
|
return element.provider === provider;
|
|
};
|
|
|
|
return providers.filter(samlProvider)[0];
|
|
}
|
|
|
|
declare module '@rocket.chat/ddp-client' {
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
interface ServerMethods {
|
|
samlLogout(provider: string): string | undefined;
|
|
}
|
|
}
|
|
|
|
Meteor.methods<ServerMethods>({
|
|
async samlLogout(provider: string) {
|
|
const userId = Meteor.userId();
|
|
// Make sure the user is logged in before we initiate SAML Logout
|
|
if (!userId) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'samlLogout' });
|
|
}
|
|
const providerConfig = getSamlServiceProviderOptions(provider);
|
|
|
|
SAMLUtils.log({ msg: 'Logout request', providerConfig });
|
|
// This query should respect upcoming array of SAML logins
|
|
const user = await Users.getSAMLByIdAndSAMLProvider(userId, provider);
|
|
if (!user?.services?.saml) {
|
|
return;
|
|
}
|
|
|
|
const { nameID, idpSession } = user.services.saml;
|
|
SAMLUtils.log({ msg: `NameID for user ${Meteor.userId()} found`, nameID });
|
|
|
|
const _saml = new SAMLServiceProvider(providerConfig);
|
|
|
|
if (!nameID || !idpSession) {
|
|
SAMLUtils.log({ msg: 'No NameID or idpSession found for user', userId });
|
|
return;
|
|
}
|
|
|
|
const request = _saml.generateLogoutRequest({
|
|
nameID: nameID || idpSession,
|
|
sessionIndex: idpSession,
|
|
});
|
|
|
|
SAMLUtils.log({ request, msg: '----Logout Request---' });
|
|
|
|
// request.request: actual XML SAML Request
|
|
// request.id: comminucation id which will be mentioned in the ResponseTo field of SAMLResponse
|
|
|
|
await Users.setSamlInResponseTo(userId, request.id);
|
|
|
|
const result = await _saml.requestToUrl(request.request, 'logout');
|
|
SAMLUtils.log({ msg: 'SAML Logout Request URL generated', result });
|
|
|
|
return result;
|
|
},
|
|
});
|