-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Rewrite 2fa to typescript (#25285)
- Loading branch information
Showing
14 changed files
with
120 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 11 additions & 4 deletions
15
.../meteor/app/2fa/server/methods/disable.js → .../meteor/app/2fa/server/methods/disable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
|
||
import { Users } from '../../../models'; | ||
import { Users } from '../../../models/server'; | ||
import { TOTP } from '../lib/totp'; | ||
|
||
Meteor.methods({ | ||
'2fa:disable'(code) { | ||
if (!Meteor.userId()) { | ||
const userId = Meteor.userId(); | ||
if (!userId) { | ||
throw new Meteor.Error('not-authorized'); | ||
} | ||
|
||
const user = Meteor.user(); | ||
|
||
if (!user) { | ||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { | ||
method: '2fa:disable', | ||
}); | ||
} | ||
|
||
const verified = TOTP.verify({ | ||
secret: user.services.totp.secret, | ||
token: code, | ||
userId: Meteor.userId(), | ||
userId, | ||
backupTokens: user.services.totp.hashedBackup, | ||
}); | ||
|
||
if (!verified) { | ||
return false; | ||
} | ||
|
||
return Users.disable2FAByUserId(Meteor.userId()); | ||
return Users.disable2FAByUserId(userId); | ||
}, | ||
}); |
13 changes: 10 additions & 3 deletions
13
apps/meteor/app/2fa/server/methods/enable.js → apps/meteor/app/2fa/server/methods/enable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 8 additions & 2 deletions
10
...p/2fa/server/methods/validateTempToken.js → ...p/2fa/server/methods/validateTempToken.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
declare module 'meteor/oauth' { | ||
import { Mongo } from 'meteor/mongo'; | ||
import { IRocketChatRecord } from '@rocket.chat/core-typings'; | ||
|
||
interface IOauthCredentials extends IRocketChatRecord { | ||
key: string; | ||
credentialSecret: string; | ||
credential: | ||
| { | ||
error: Error; | ||
} | ||
| string; | ||
} | ||
|
||
namespace OAuth { | ||
function _redirectUri(serviceName: string, config: any, params: any, absoluteUrlOptions: any): string; | ||
function _retrieveCredentialSecret(credentialToken: string): string | null; | ||
function _retrievePendingCredential(key: string, ...args: string[]): void; | ||
function openSecret(secret: string): string; | ||
const _storageTokenPrefix: string; | ||
const _pendingCredentials: Mongo.Collection<IOauthCredentials>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters