Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor the refresh oauth services function #31385

Merged
merged 40 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
cffcb32
fix: login buttons remain visible until refresh after disabling authe…
pierre-lehnen-rc Jan 3, 2024
74c850c
chore: convert login services files to typescript and refactor the re…
pierre-lehnen-rc Jan 5, 2024
19a4821
login service configuration type
pierre-lehnen-rc Jan 5, 2024
9b0ef66
added tests for oauth button
pierre-lehnen-rc Jan 5, 2024
9287011
Merge branch 'develop' into chore/refresh-oauth-services
pierre-lehnen-rc Jan 5, 2024
b92a6ab
Merge branch 'fix/login-buttons-not-hiding' into chore/refresh-oauth-…
pierre-lehnen-rc Jan 5, 2024
6815b8a
types
pierre-lehnen-rc Jan 5, 2024
766d451
types
pierre-lehnen-rc Jan 7, 2024
6bdd9c6
review changes
pierre-lehnen-rc Jan 7, 2024
8eb1cd6
Merge branch 'fix/login-buttons-not-hiding' into chore/refresh-oauth-…
pierre-lehnen-rc Jan 7, 2024
bbfbeb9
debugging CI tests
pierre-lehnen-rc Jan 8, 2024
0a8bf53
Merge branch 'fix/login-buttons-not-hiding' into chore/refresh-oauth-…
pierre-lehnen-rc Jan 8, 2024
c3d8f4a
lint
pierre-lehnen-rc Jan 8, 2024
74f6b88
use insert/update instead of upsert
pierre-lehnen-rc Jan 8, 2024
84b130f
avoid unnecessary query
pierre-lehnen-rc Jan 8, 2024
1288abe
API e2e test
pierre-lehnen-rc Jan 8, 2024
a9f3ebf
avoid unnecessary query
pierre-lehnen-rc Jan 8, 2024
008d0c0
Merge branch 'fix/login-buttons-not-hiding' into chore/refresh-oauth-…
pierre-lehnen-rc Jan 8, 2024
000a14b
logs for desperate CI debugging
pierre-lehnen-rc Jan 8, 2024
2a6eb51
more logs, timestamps
pierre-lehnen-rc Jan 8, 2024
a6ef7dc
websocket logs
pierre-lehnen-rc Jan 9, 2024
a074ae2
Merge branch 'develop' into chore/refresh-oauth-services
pierre-lehnen-rc Jan 9, 2024
1ee828a
yet more logs
pierre-lehnen-rc Jan 9, 2024
4353af5
getting close
pierre-lehnen-rc Jan 9, 2024
726979f
ts
pierre-lehnen-rc Jan 9, 2024
b194acf
removed logs
pierre-lehnen-rc Jan 10, 2024
40bb2c9
configure oauth before page load
pierre-lehnen-rc Jan 10, 2024
aaa9001
moved existing authentication code to a new provider
pierre-lehnen-rc Jan 12, 2024
328d2a4
fix 'service.configurations' endpoint definition
pierre-lehnen-rc Jan 12, 2024
b54e487
load login buttons from the rest API instead of the local collection
pierre-lehnen-rc Jan 12, 2024
6827114
missed references
pierre-lehnen-rc Jan 12, 2024
0090867
Merge branch 'develop' into chore/refresh-oauth-services
pierre-lehnen-rc Jan 16, 2024
bb29f64
Merge branch 'develop' into chore/refresh-oauth-services
pierre-lehnen-rc Jan 18, 2024
d3a59a2
chore: remove client references to the service configurations collect…
pierre-lehnen-rc Jan 18, 2024
835dbbf
Merge branch 'develop' into chore/refresh-oauth-services
pierre-lehnen-rc Jan 21, 2024
5bbf7af
Merge branch 'develop' into chore/refresh-oauth-services
pierre-lehnen-rc Jan 22, 2024
91c465c
Merge branch 'develop' into chore/refresh-oauth-services
pierre-lehnen-rc Jan 23, 2024
51c9e15
merge fixes
pierre-lehnen-rc Jan 23, 2024
a7b64a2
merge fixes
pierre-lehnen-rc Jan 23, 2024
770052e
renamed configuration function
pierre-lehnen-rc Jan 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/methods/addOAuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { ServerMethods } from '@rocket.chat/ui-contexts';
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';

import { addOAuthService } from '../../../../server/lib/oauth/addOAuthService';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { addOAuthService } from '../functions/addOAuthService';

declare module '@rocket.chat/ui-contexts' {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down
7 changes: 2 additions & 5 deletions apps/meteor/app/lib/server/methods/refreshOAuthService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Settings } from '@rocket.chat/models';
import type { ServerMethods } from '@rocket.chat/ui-contexts';
import { Meteor } from 'meteor/meteor';
import { ServiceConfiguration } from 'meteor/service-configuration';

import { refreshLoginServices } from '../../../../server/lib/refreshLoginServices';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';

declare module '@rocket.chat/ui-contexts' {
Expand All @@ -29,8 +28,6 @@ Meteor.methods<ServerMethods>({
});
}

await ServiceConfiguration.configurations.removeAsync({});

await Settings.update({ _id: /^(Accounts_OAuth_|SAML_|CAS_).+/ }, { $set: { _updatedAt: new Date() } }, { multi: true });
await refreshLoginServices();
},
});
5 changes: 0 additions & 5 deletions apps/meteor/app/lib/server/startup/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { customOAuthServicesInit } from './oAuthServicesUpdate';
import './rateLimiter';
import './robots';
import './settingsOnLoadCdnPrefix';
import './settingsOnLoadDirectReply';
import './settingsOnLoadSMTP';

export const libStartup = async () => {
await customOAuthServicesInit();
};
204 changes: 0 additions & 204 deletions apps/meteor/app/lib/server/startup/oAuthServicesUpdate.js

This file was deleted.

22 changes: 7 additions & 15 deletions apps/meteor/app/meteor-accounts-saml/server/lib/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { SAMLConfiguration } from '@rocket.chat/core-typings';
import { LoginServiceConfiguration } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';
import { ServiceConfiguration } from 'meteor/service-configuration';

import { SystemLogger } from '../../../../server/lib/logger/system';
import { settings, settingsRegistry } from '../../../settings/server';
Expand All @@ -17,13 +18,13 @@ import {
defaultMetadataCertificateTemplate,
} from './constants';

const getSamlConfigs = function (service: string): Record<string, any> {
const configs = {
const getSamlConfigs = function (service: string): SAMLConfiguration {
const configs: SAMLConfiguration = {
buttonLabelText: settings.get(`${service}_button_label_text`),
buttonLabelColor: settings.get(`${service}_button_label_color`),
buttonColor: settings.get(`${service}_button_color`),
clientConfig: {
provider: settings.get(`${service}_provider`),
provider: settings.get<string>(`${service}_provider`),
},
entryPoint: settings.get(`${service}_entry_point`),
idpSLORedirectURL: settings.get(`${service}_idp_slo_redirect_url`),
Expand Down Expand Up @@ -115,19 +116,10 @@ export const loadSamlServiceProviders = async function (): Promise<void> {
if (value === true) {
const samlConfigs = getSamlConfigs(key);
SAMLUtils.log(key);
await ServiceConfiguration.configurations.upsertAsync(
{
service: serviceName.toLowerCase(),
},
{
$set: samlConfigs,
},
);
await LoginServiceConfiguration.createOrUpdateService(serviceName, samlConfigs);
return configureSamlService(samlConfigs);
}
await ServiceConfiguration.configurations.removeAsync({
service: serviceName.toLowerCase(),
});
await LoginServiceConfiguration.removeService(serviceName);
return false;
}),
)
Expand Down
18 changes: 9 additions & 9 deletions apps/meteor/ee/server/configuration/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ interface IOAuthUserIdentity {
}

interface IOAuthSettings {
mapChannels: string;
mergeRoles: string;
mapChannels: boolean;
mergeRoles: boolean;
rolesToSync: string;
rolesClaim: string;
groupsClaim: string;
Expand All @@ -34,13 +34,13 @@ const logger = new Logger('EECustomOAuth');

function getOAuthSettings(serviceName: string): IOAuthSettings {
return {
mapChannels: settings.get(`Accounts_OAuth_Custom-${serviceName}-map_channels`) as string,
mergeRoles: settings.get(`Accounts_OAuth_Custom-${serviceName}-merge_roles`) as string,
rolesToSync: settings.get(`Accounts_OAuth_Custom-${serviceName}-roles_to_sync`) as string,
rolesClaim: settings.get(`Accounts_OAuth_Custom-${serviceName}-roles_claim`) as string,
groupsClaim: settings.get(`Accounts_OAuth_Custom-${serviceName}-groups_claim`) as string,
channelsAdmin: settings.get(`Accounts_OAuth_Custom-${serviceName}-channels_admin`) as string,
channelsMap: settings.get(`Accounts_OAuth_Custom-${serviceName}-groups_channel_map`) as string,
mapChannels: settings.get<boolean>(`Accounts_OAuth_Custom-${serviceName}-map_channels`),
mergeRoles: settings.get<boolean>(`Accounts_OAuth_Custom-${serviceName}-merge_roles`),
rolesToSync: settings.get<string>(`Accounts_OAuth_Custom-${serviceName}-roles_to_sync`),
rolesClaim: settings.get<string>(`Accounts_OAuth_Custom-${serviceName}-roles_claim`),
groupsClaim: settings.get<string>(`Accounts_OAuth_Custom-${serviceName}-groups_claim`),
channelsAdmin: settings.get<string>(`Accounts_OAuth_Custom-${serviceName}-channels_admin`),
channelsMap: settings.get<string>(`Accounts_OAuth_Custom-${serviceName}-groups_channel_map`),
};
}

Expand Down
Loading
Loading