-
Notifications
You must be signed in to change notification settings - Fork 13.9k
chore: Passport Nextcloud OAuth #40591
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,12 @@ | ||
| import type { OauthConfig } from '@rocket.chat/core-typings'; | ||
| import type { OAuthConfiguration } from '@rocket.chat/core-typings'; | ||
| import { Meteor } from 'meteor/meteor'; | ||
| import _ from 'underscore'; | ||
|
|
||
| import { CustomOAuth } from '../../custom-oauth/server/custom_oauth_server'; | ||
| import { settings } from '../../settings/server'; | ||
| import { addPassportCustomOAuth } from '../../../server/lib/oauth/addPassportCustomOAuth'; | ||
| import { settings } from '../../settings/server/cached'; | ||
|
|
||
| const config: OauthConfig = { | ||
| serverURL: '', | ||
| const NEXTCLOUD_PATHS = { | ||
| tokenPath: '/index.php/apps/oauth2/api/v1/token', | ||
| tokenSentVia: 'header', | ||
| tokenSentVia: 'header' as OAuthConfiguration['tokenSentVia'], | ||
| authorizePath: '/index.php/apps/oauth2/authorize', | ||
| identityPath: '/ocs/v2.php/cloud/user?format=json', | ||
| scope: 'openid', | ||
|
|
@@ -18,20 +16,31 @@ const config: OauthConfig = { | |
| }, | ||
| }; | ||
|
|
||
| const Nextcloud = new CustomOAuth('nextcloud', config); | ||
| function configureNextcloudOAuth(): void { | ||
| const enabled = settings.get<boolean>('Accounts_OAuth_Nextcloud'); | ||
| if (!enabled) { | ||
| return; | ||
| } | ||
|
|
||
| const fillServerURL = _.debounce((): void => { | ||
| const nextcloudURL = settings.get<string>('Accounts_OAuth_Nextcloud_URL'); | ||
| if (!nextcloudURL) { | ||
| if (nextcloudURL === undefined) { | ||
| return fillServerURL(); | ||
| } | ||
| const serverURL = settings.get<string>('Accounts_OAuth_Nextcloud_URL')?.trim().replace(/\/*$/, ''); | ||
| const clientId = settings.get<string>('Accounts_OAuth_Nextcloud_id'); | ||
| const clientSecret = settings.get<string>('Accounts_OAuth_Nextcloud_secret'); | ||
|
|
||
| if (!serverURL || !clientId || !clientSecret) { | ||
| return; | ||
| } | ||
| config.serverURL = nextcloudURL.trim().replace(/\/*$/, ''); | ||
| return Nextcloud.configure(config); | ||
| }, 1000); | ||
|
|
||
| addPassportCustomOAuth('nextcloud', { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Re-registering Nextcloud OAuth on every settings change adds duplicate Express routes, because Prompt for AI agents |
||
| ...NEXTCLOUD_PATHS, | ||
| serverURL, | ||
| clientId, | ||
| clientSecret, | ||
| }); | ||
|
Comment on lines
+19
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Inspect addPassportCustomOAuth implementation:"
fd -i 'addPassportCustomOAuth.ts' | while read -r file; do
echo "== $file =="
sed -n '1,240p' "$file"
done
echo
echo "Search for existing OAuth teardown helpers:"
rg -n -C3 'passport\.unuse|removePassportCustomOAuth|unregister.*OAuth|disable.*OAuth' --type=tsRepository: RocketChat/Rocket.Chat Length of output: 3176 Call When Nextcloud OAuth is disabled or credentials become incomplete, the function returns without deregistering the strategy. Since Add 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| Meteor.startup(() => { | ||
| settings.watch('Accounts_OAuth_Nextcloud_URL', () => fillServerURL()); | ||
| settings.watchMultiple( | ||
| ['Accounts_OAuth_Nextcloud', 'Accounts_OAuth_Nextcloud_URL', 'Accounts_OAuth_Nextcloud_id', 'Accounts_OAuth_Nextcloud_secret'], | ||
| configureNextcloudOAuth, | ||
| ); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The disabled branch returns without unregistering previously configured Nextcloud Passport auth, so OAuth can remain active after the setting is turned off.
Prompt for AI agents