-
Notifications
You must be signed in to change notification settings - Fork 13.6k
chore: Passport Gitlab OAuth #40609
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: Passport Gitlab OAuth #40609
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,11 +1,12 @@ | ||
| import type { OauthConfig } from '@rocket.chat/core-typings'; | ||
| import type { OAuthConfiguration } from '@rocket.chat/core-typings'; | ||
| import { Meteor } from 'meteor/meteor'; | ||
| import passport from 'passport'; | ||
| import _ from 'underscore'; | ||
|
|
||
| import { CustomOAuth } from '../../custom-oauth/server/custom_oauth_server'; | ||
| import { addPassportCustomOAuth } from '../../../server/lib/oauth/addPassportCustomOAuth'; | ||
| import { settings } from '../../settings/server'; | ||
|
|
||
| const config: OauthConfig = { | ||
| const config: Partial<OAuthConfiguration> = { | ||
| serverURL: 'https://gitlab.com', | ||
| identityPath: '/api/v4/user', | ||
| scope: 'read_user', | ||
|
|
@@ -17,15 +18,39 @@ const config: OauthConfig = { | |
| accessTokenParam: 'access_token', | ||
| }; | ||
|
|
||
| const Gitlab = new CustomOAuth('gitlab', config); | ||
| const configureGitlabOAuth = () => { | ||
| passport.unuse('gitlab'); | ||
|
|
||
| const enabled = settings.get<boolean>('Accounts_OAuth_Gitlab'); | ||
| if (!enabled) { | ||
| return; | ||
| } | ||
|
|
||
| const clientId = settings.get<string>('Accounts_OAuth_Gitlab_id'); | ||
| const clientSecret = settings.get<string>('Accounts_OAuth_Gitlab_secret'); | ||
| const serverURL = settings.get<string>('API_Gitlab_URL').trim().replace(/\/*$/, '') || config.serverURL; | ||
| const identityPath = settings.get<string>('Accounts_OAuth_Gitlab_identity_path') || config.identityPath; | ||
| const mergeUsers = Boolean(settings.get<boolean>('Accounts_OAuth_Gitlab_merge_users')); | ||
|
|
||
| if (!clientId || !clientSecret) { | ||
| return; | ||
| } | ||
|
|
||
| addPassportCustomOAuth('gitlab', { ...config, clientId, clientSecret, serverURL, identityPath, mergeUsers }); | ||
|
Member
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. When the settings are changed, the addPassportCustomOAuth re adds the endpoint routes. Will it have impact on memory (duplications) or are the routes just overwritten? Rest everything LGTM.
Member
Author
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. I was checking this, I assumed it will overwrite but sadly no, it adds middlewares to the chain. For our implementation it shouldn't create any impact as we send a response, so it never goes to stacked middleware. I'll open a task to improve this, for now it should increase a little memory consumption if routes are over-written many times. |
||
| }; | ||
|
|
||
| Meteor.startup(() => { | ||
| const updateConfig = _.debounce(() => { | ||
| config.serverURL = settings.get<string>('API_Gitlab_URL').trim().replace(/\/*$/, '') || config.serverURL; | ||
| config.identityPath = settings.get('Accounts_OAuth_Gitlab_identity_path') || config.identityPath; | ||
| config.mergeUsers = Boolean(settings.get<boolean>('Accounts_OAuth_Gitlab_merge_users')); | ||
| Gitlab.configure(config); | ||
| }, 300); | ||
|
|
||
| settings.watchMultiple(['API_Gitlab_URL', 'Accounts_OAuth_Gitlab_identity_path', 'Accounts_OAuth_Gitlab_merge_users'], updateConfig); | ||
| const updateConfig = _.debounce(configureGitlabOAuth, 300); | ||
|
|
||
| settings.watchMultiple( | ||
| [ | ||
| 'Accounts_OAuth_Gitlab', | ||
| 'API_Gitlab_URL', | ||
| 'Accounts_OAuth_Gitlab_id', | ||
| 'Accounts_OAuth_Gitlab_secret', | ||
| 'Accounts_OAuth_Gitlab_identity_path', | ||
| 'Accounts_OAuth_Gitlab_merge_users', | ||
| ], | ||
| updateConfig, | ||
| ); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.