Files
wekan/server/saml.js
T
Lauri Ojansivu d6503b43f5 Choose which SAML signatures are required and log in by full-page redirect.
SAML 2.0 lets an identity provider sign the Response, the Assertion or
both. WeKan always required a signed Response (node-saml's default, never
overridden), so an identity provider that signs only the Assertion was
rejected with "Invalid document signature" before the Assertion was
checked. Admin Panel -> People -> SAML now has SAML_IDP_PROFILE: standard,
which keeps the previous behaviour, or signed-assertion-redirect, which
requires the Assertion signature instead and logs in by full-page redirect.
SAML_WANT_RESPONSE_SIGNED, SAML_WANT_ASSERTIONS_SIGNED and SAML_LOGIN_FLOW
can each be set on their own; left at Default they follow the profile. A
configuration requiring neither signature is refused, and validation
errors now reach the administrator instead of "Internal server error".

In redirect mode the ACS stores the validated profile under the random
credential token and redirects to /sign-in?samlToken=; the page exchanges
it and opens /. The assertion never enters the address. The token is
remembered in the tab that started the login, and a samlToken that tab did
not start is not exchanged, so a link cannot sign a browser into another
account. Errors return as samlError and are shown on the sign-in page.

A test signs responses with a throwaway key and runs them through the
shipped node-saml; browser tests log in through the fixture identity
provider in both flows. The new message is English, pending Transifex.

Thanks to xet7 !
2026-09-29 13:57:51 +03:00

62 lines
2.2 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { ServiceConfiguration } from 'meteor/service-configuration';
import Settings from '/models/settings';
const { cleanSamlOverrides, resolveSamlConfig, validateSamlConfig } = require('/models/lib/samlConfig');
export async function samlConfiguration() {
const setting = await Settings.findOneAsync({});
return resolveSamlConfig(setting?.saml || {});
}
export async function reconfigureSaml() {
const { config } = await samlConfiguration();
if (!config.enabled) {
await ServiceConfiguration.configurations.removeAsync({ service: 'saml' });
return;
}
validateSamlConfig(config);
await ServiceConfiguration.configurations.upsertAsync({ service: 'saml' }, { $set: config });
}
Meteor.startup(async () => {
await reconfigureSaml();
});
Meteor.methods({
async getSamlConfigSources() {
const user = await Meteor.userAsync();
if (user?.isAdmin !== true) throw new Meteor.Error('error-notAuthorized');
const setting = await Settings.findOneAsync({});
const { config, sources } = resolveSamlConfig(setting?.saml || {});
return {
overrides: setting?.saml || {}, sources,
urls: {
service: Meteor.absoluteUrl(`_saml/validate/${config.provider}`),
logout: Meteor.absoluteUrl(`_saml/logout/${config.provider}`),
metadata: Meteor.absoluteUrl(`_saml/config/${config.provider}`),
},
};
},
async saveSamlSettings(input) {
check(input, Object);
const user = await Meteor.userAsync();
if (user?.isAdmin !== true) throw new Meteor.Error('error-notAuthorized');
// Validation errors are plain TypeErrors, which Meteor would report to
// the administrator only as "Internal server error".
let clean;
try {
clean = cleanSamlOverrides(input);
validateSamlConfig(resolveSamlConfig(clean).config);
} catch (error) {
if (error instanceof TypeError) throw new Meteor.Error('invalid-saml-settings', error.message);
throw error;
}
const setting = await Settings.findOneAsync({});
if (!setting) throw new Meteor.Error('settings-not-found');
await Settings.updateAsync(setting._id, { $set: { saml: clean } });
await reconfigureSaml();
return true;
},
});