@@ -18,6 +18,7 @@ import {
1818 isUsersSetPreferencesParamsPOST ,
1919 isUsersCheckUsernameAvailabilityParamsGET ,
2020 isUsersSendConfirmationEmailParamsPOST ,
21+ ajv ,
2122} from '@rocket.chat/rest-typings' ;
2223import { getLoginExpirationInMs , wrapExceptions } from '@rocket.chat/tools' ;
2324import { Accounts } from 'meteor/accounts-base' ;
@@ -69,6 +70,7 @@ import { deleteUserOwnAccount } from '../../../lib/server/methods/deleteUserOwnA
6970import { settings } from '../../../settings/server' ;
7071import { isSMTPConfigured } from '../../../utils/server/functions/isSMTPConfigured' ;
7172import { getURL } from '../../../utils/server/getURL' ;
73+ import type { ExtractRoutesFromAPI } from '../ApiClass' ;
7274import { API } from '../api' ;
7375import { getPaginationItems } from '../helpers/getPaginationItems' ;
7476import { getUserFromParams } from '../helpers/getUserFromParams' ;
@@ -761,17 +763,70 @@ API.v1.addRoute(
761763 } ,
762764) ;
763765
764- API . v1 . addRoute (
766+ const usersEndpoints = API . v1 . post (
765767 'users.createToken' ,
766- { authRequired : true , deprecationVersion : '8.0.0' } ,
767768 {
768- async post ( ) {
769- const user = await getUserFromParams ( this . bodyParams ) ;
769+ authRequired : true ,
770+ body : ajv . compile < { userId : string ; secret : string } > ( {
771+ type : 'object' ,
772+ properties : {
773+ userId : {
774+ type : 'string' ,
775+ minLength : 1 ,
776+ } ,
777+ secret : {
778+ type : 'string' ,
779+ minLength : 1 ,
780+ } ,
781+ } ,
782+ required : [ 'userId' , 'secret' ] ,
783+ additionalProperties : false ,
784+ } ) ,
785+ response : {
786+ 200 : ajv . compile < { data : { userId : string ; authToken : string } } > ( {
787+ type : 'object' ,
788+ properties : {
789+ data : {
790+ type : 'object' ,
791+ properties : {
792+ userId : {
793+ type : 'string' ,
794+ minLength : 1 ,
795+ } ,
796+ authToken : {
797+ type : 'string' ,
798+ minLength : 1 ,
799+ } ,
800+ } ,
801+ required : [ 'userId' ] ,
802+ additionalProperties : false ,
803+ } ,
804+ success : {
805+ type : 'boolean' ,
806+ enum : [ true ] ,
807+ } ,
808+ } ,
809+ required : [ 'data' , 'success' ] ,
810+ additionalProperties : false ,
811+ } ) ,
812+ 400 : ajv . compile ( {
813+ type : 'object' ,
814+ properties : {
815+ success : { type : 'boolean' , enum : [ false ] } ,
816+ error : { type : 'string' } ,
817+ errorType : { type : 'string' } ,
818+ } ,
819+ required : [ 'success' ] ,
820+ additionalProperties : false ,
821+ } ) ,
822+ } ,
823+ } ,
824+ async function action ( ) {
825+ const user = await getUserFromParams ( this . bodyParams ) ;
770826
771- const data = await generateAccessToken ( this . userId , user . _id ) ;
827+ const data = await generateAccessToken ( user . _id , this . bodyParams . secret ) ;
772828
773- return data ? API . v1 . success ( { data } ) : API . v1 . forbidden ( ) ;
774- } ,
829+ return API . v1 . success ( { data } ) ;
775830 } ,
776831) ;
777832
@@ -1441,3 +1496,10 @@ settings.watch<number>('Rate_Limiter_Limit_RegisterUser', (value) => {
14411496
14421497 API . v1 . updateRateLimiterDictionaryForRoute ( userRegisterRoute , value ) ;
14431498} ) ;
1499+
1500+ type UsersEndpoints = ExtractRoutesFromAPI < typeof usersEndpoints > ;
1501+
1502+ declare module '@rocket.chat/rest-typings' {
1503+ // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
1504+ interface Endpoints extends UsersEndpoints { }
1505+ }
0 commit comments