-
Notifications
You must be signed in to change notification settings - Fork 11.7k
chore: remove dependency on meteor's oauth packages #35877
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
base: develop
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -15,15 +15,15 @@ rocketchat:user-presence | |
|
||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
|
||
[email protected] | ||
[email protected] | ||
# oauth1 is used only by twitter oauth | ||
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. # oauth1 is used for OAuth 1.0 implementations The comment about oauth1 being used only by Twitter OAuth is misleading since accounts-twitter has been removed. This issue appears in multiple locations:
Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
[email protected] | ||
[email protected] | ||
|
||
[email protected] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
|
@@ -35,7 +33,6 @@ [email protected] | |
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
|
@@ -85,7 +82,6 @@ [email protected] | |
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Meteor } from 'meteor/meteor'; | ||
|
||
export type RequestCredentialOptions = Meteor.LoginWithExternalServiceOptions; | ||
export type RequestCredentialCallback = (credentialTokenOrError?: string | Error) => void; | ||
|
||
// Receives a function that accepts an options object and an optional callback | ||
// Returns the same function but with the signature changed to also accept only the callback | ||
// With this, you can make a function that accepts the arguments in any way that Meteor's login handlers may send them, without having to validate the params or mess with the signature types | ||
export function wrapLoginHandlerFn( | ||
loginHandlerFn: (options: RequestCredentialOptions, callback?: RequestCredentialCallback) => Promise<void> | void, | ||
) { | ||
return (options?: RequestCredentialOptions | RequestCredentialCallback, callback?: RequestCredentialCallback) => { | ||
if (!callback && typeof options === 'function') { | ||
return loginHandlerFn({}, options); | ||
} | ||
|
||
return loginHandlerFn(options as RequestCredentialOptions, callback); | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Accounts } from 'meteor/accounts-base'; | ||
|
||
import { createOAuthTotpLoginMethod } from './oauth'; | ||
import type { IOAuthProvider } from '../../definitions/IOAuthProvider'; | ||
import { overrideLoginMethod, type LoginCallback } from '../../lib/2fa/overrideLoginMethod'; | ||
import { wrapLoginHandlerFn } from '../../lib/wrapLoginHandlerFn'; | ||
|
||
export const createOAuthLoginFn = (provider: IOAuthProvider) => { | ||
const loginHandler = wrapLoginHandlerFn((options, callback) => { | ||
const credentialRequestCompleteCallback = Accounts.oauth.credentialRequestCompleteHandler(callback); | ||
provider.requestCredential(options, credentialRequestCompleteCallback); | ||
}); | ||
|
||
Accounts.oauth.registerService(provider.name); | ||
Accounts.registerClientLoginFunction(provider.name, loginHandler); | ||
|
||
const loginWithProvider = (options: Meteor.LoginWithExternalServiceOptions | undefined, cb: LoginCallback) => | ||
Accounts.applyLoginFunction(provider.name, [options, cb]); | ||
|
||
const loginWithProviderAndTOTP = createOAuthTotpLoginMethod(provider); | ||
|
||
return (options: Meteor.LoginWithExternalServiceOptions | undefined, callback?: LoginCallback) => { | ||
overrideLoginMethod(loginWithProvider, [options], callback, loginWithProviderAndTOTP); | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
import { Random } from '@rocket.chat/random'; | ||
import { Accounts } from 'meteor/accounts-base'; | ||
import { Github } from 'meteor/github-oauth'; | ||
import { Meteor } from 'meteor/meteor'; | ||
import { OAuth } from 'meteor/oauth'; | ||
|
||
import { createOAuthTotpLoginMethod } from './oauth'; | ||
import { overrideLoginMethod } from '../../lib/2fa/overrideLoginMethod'; | ||
import { createOAuthLoginFn } from './createOAuthLoginFn'; | ||
import { wrapRequestCredentialFn } from '../../lib/wrapRequestCredentialFn'; | ||
|
||
const { loginWithGithub } = Meteor; | ||
const loginWithGithubAndTOTP = createOAuthTotpLoginMethod(Github); | ||
Meteor.loginWithGithub = (options, callback) => { | ||
overrideLoginMethod(loginWithGithub, [options], callback, loginWithGithubAndTOTP); | ||
}; | ||
Meteor.loginWithGithub = createOAuthLoginFn({ | ||
name: 'github', | ||
|
||
Github.requestCredential = wrapRequestCredentialFn('github', ({ config, loginStyle, options, credentialRequestCompleteCallback }) => { | ||
const credentialToken = Random.secret(); | ||
const scope = options?.requestPermissions || ['user:email']; | ||
const flatScope = scope.map(encodeURIComponent).join('+'); | ||
requestCredential: wrapRequestCredentialFn('github', ({ config, loginStyle, options, credentialRequestCompleteCallback }) => { | ||
const credentialToken = Random.secret(); | ||
const scope = options?.requestPermissions || ['user:email']; | ||
const flatScope = scope.map(encodeURIComponent).join('+'); | ||
|
||
let allowSignup = ''; | ||
if (Accounts._options?.forbidClientAccountCreation) { | ||
allowSignup = '&allow_signup=false'; | ||
} | ||
let allowSignup = ''; | ||
if (Accounts._options?.forbidClientAccountCreation) { | ||
allowSignup = '&allow_signup=false'; | ||
} | ||
|
||
const loginUrl = | ||
`https://github.com/login/oauth/authorize` + | ||
`?client_id=${config.clientId}` + | ||
`&scope=${flatScope}` + | ||
`&redirect_uri=${OAuth._redirectUri('github', config)}` + | ||
`&state=${OAuth._stateParam(loginStyle, credentialToken, options.redirectUrl)}${allowSignup}`; | ||
const loginUrl = | ||
`https://github.com/login/oauth/authorize` + | ||
`?client_id=${config.clientId}` + | ||
`&scope=${flatScope}` + | ||
`&redirect_uri=${OAuth._redirectUri('github', config)}` + | ||
`&state=${OAuth._stateParam(loginStyle, credentialToken, options.redirectUrl)}${allowSignup}`; | ||
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. &state=${OAuth._stateParam(loginStyle, credentialToken, options?.redirectUrl)}${allowSignup}`; The code accesses This issue appears in multiple locations:
Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
|
||
OAuth.launchLogin({ | ||
loginService: 'github', | ||
loginStyle, | ||
loginUrl, | ||
credentialRequestCompleteCallback, | ||
credentialToken, | ||
popupOptions: { width: 900, height: 450 }, | ||
}); | ||
OAuth.launchLogin({ | ||
loginService: 'github', | ||
loginStyle, | ||
loginUrl, | ||
credentialRequestCompleteCallback, | ||
credentialToken, | ||
popupOptions: { width: 900, height: 450 }, | ||
}); | ||
}), | ||
}); |
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.
The removal of accounts-github and accounts-twitter packages should be documented in the changelog or migration guide as it's a breaking change for users relying on these authentication methods.
This issue appears in multiple locations:
Please document the removal of these packages in the changelog or migration guide to inform users of this breaking change.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.