@@ -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' ;
@@ -756,17 +758,70 @@ API.v1.addRoute(
756758 } ,
757759) ;
758760
759- API . v1 . addRoute (
761+ const usersEndpoints = API . v1 . post (
760762 'users.createToken' ,
761- { authRequired : true , deprecationVersion : '8.0.0' } ,
762763 {
763- async post ( ) {
764- const user = await getUserFromParams ( this . bodyParams ) ;
764+ authRequired : true ,
765+ body : ajv . compile < { userId : string ; secret : string } > ( {
766+ type : 'object' ,
767+ properties : {
768+ userId : {
769+ type : 'string' ,
770+ minLength : 1 ,
771+ } ,
772+ secret : {
773+ type : 'string' ,
774+ minLength : 1 ,
775+ } ,
776+ } ,
777+ required : [ 'userId' , 'secret' ] ,
778+ additionalProperties : false ,
779+ } ) ,
780+ response : {
781+ 200 : ajv . compile < { data : { userId : string ; authToken : string } } > ( {
782+ type : 'object' ,
783+ properties : {
784+ data : {
785+ type : 'object' ,
786+ properties : {
787+ userId : {
788+ type : 'string' ,
789+ minLength : 1 ,
790+ } ,
791+ authToken : {
792+ type : 'string' ,
793+ minLength : 1 ,
794+ } ,
795+ } ,
796+ required : [ 'userId' ] ,
797+ additionalProperties : false ,
798+ } ,
799+ success : {
800+ type : 'boolean' ,
801+ enum : [ true ] ,
802+ } ,
803+ } ,
804+ required : [ 'data' , 'success' ] ,
805+ additionalProperties : false ,
806+ } ) ,
807+ 400 : ajv . compile ( {
808+ type : 'object' ,
809+ properties : {
810+ success : { type : 'boolean' , enum : [ false ] } ,
811+ error : { type : 'string' } ,
812+ errorType : { type : 'string' } ,
813+ } ,
814+ required : [ 'success' ] ,
815+ additionalProperties : false ,
816+ } ) ,
817+ } ,
818+ } ,
819+ async function action ( ) {
820+ const user = await getUserFromParams ( this . bodyParams ) ;
765821
766- const data = await generateAccessToken ( this . userId , user . _id ) ;
822+ const data = await generateAccessToken ( user . _id , this . bodyParams . secret ) ;
767823
768- return data ? API . v1 . success ( { data } ) : API . v1 . forbidden ( ) ;
769- } ,
824+ return API . v1 . success ( { data } ) ;
770825 } ,
771826) ;
772827
@@ -1429,3 +1484,10 @@ settings.watch<number>('Rate_Limiter_Limit_RegisterUser', (value) => {
14291484
14301485 API . v1 . updateRateLimiterDictionaryForRoute ( userRegisterRoute , value ) ;
14311486} ) ;
1487+
1488+ type UsersEndpoints = ExtractRoutesFromAPI < typeof usersEndpoints > ;
1489+
1490+ declare module '@rocket.chat/rest-typings' {
1491+ // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
1492+ interface Endpoints extends UsersEndpoints { }
1493+ }
0 commit comments