Chore: Rewrite 2fa to typescript (#25285)
parent
c731037a31
commit
d4f4e550e1
@ -1,19 +1,26 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { Users } from '../../../models'; |
||||
import { Users } from '../../../models/server'; |
||||
import { TOTP } from '../lib/totp'; |
||||
|
||||
Meteor.methods({ |
||||
'2fa:enable'() { |
||||
if (!Meteor.userId()) { |
||||
const userId = Meteor.userId(); |
||||
if (!userId) { |
||||
throw new Meteor.Error('not-authorized'); |
||||
} |
||||
|
||||
const user = Meteor.user(); |
||||
|
||||
if (!user || !user.username) { |
||||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { |
||||
method: '2fa:enable', |
||||
}); |
||||
} |
||||
|
||||
const secret = TOTP.generateSecret(); |
||||
|
||||
Users.disable2FAAndSetTempSecretByUserId(Meteor.userId(), secret.base32); |
||||
Users.disable2FAAndSetTempSecretByUserId(userId, secret.base32); |
||||
|
||||
return { |
||||
secret: secret.base32, |
||||
@ -1,15 +1,21 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { Users } from '../../../models'; |
||||
import { Users } from '../../../models/server'; |
||||
import { TOTP } from '../lib/totp'; |
||||
|
||||
Meteor.methods({ |
||||
'2fa:validateTempToken'(userToken) { |
||||
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:validateTempToken', |
||||
}); |
||||
} |
||||
|
||||
if (!user.services || !user.services.totp || !user.services.totp.tempSecret) { |
||||
throw new Meteor.Error('invalid-totp'); |
||||
@ -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>; |
||||
} |
||||
} |
||||
|
||||
Loading…
Reference in new issue