mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 04:02:54 -06:00
feat: the created instance token can now also be optionally defined manually in the creation endpoint
This commit is contained in:
parent
1b7015c0df
commit
30cd8a03eb
@ -13,6 +13,7 @@
|
|||||||
* Added configuration of events by webhook of instances
|
* Added configuration of events by webhook of instances
|
||||||
* Now the api key can be exposed in fetch instances if the EXPOSE_IN_FETCH_INSTANCES variable is set to true
|
* Now the api key can be exposed in fetch instances if the EXPOSE_IN_FETCH_INSTANCES variable is set to true
|
||||||
* Added option to generate qrcode as soon as the instance is created
|
* Added option to generate qrcode as soon as the instance is created
|
||||||
|
* The created instance token can now also be optionally defined manually in the creation endpoint
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ export const instanceNameSchema: JSONSchema7 = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
qrcode: { type: 'boolean', enum: [true, false] },
|
qrcode: { type: 'boolean', enum: [true, false] },
|
||||||
|
token: { type: 'string' },
|
||||||
},
|
},
|
||||||
...isNotEmpty('instanceName'),
|
...isNotEmpty('instanceName'),
|
||||||
};
|
};
|
||||||
|
@ -23,7 +23,13 @@ export class InstanceController {
|
|||||||
|
|
||||||
private readonly logger = new Logger(InstanceController.name);
|
private readonly logger = new Logger(InstanceController.name);
|
||||||
|
|
||||||
public async createInstance({ instanceName, webhook, events, qrcode }: InstanceDto) {
|
public async createInstance({
|
||||||
|
instanceName,
|
||||||
|
webhook,
|
||||||
|
events,
|
||||||
|
qrcode,
|
||||||
|
token,
|
||||||
|
}: InstanceDto) {
|
||||||
const mode = this.configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
|
const mode = this.configService.get<Auth>('AUTHENTICATION').INSTANCE.MODE;
|
||||||
|
|
||||||
if (mode === 'container') {
|
if (mode === 'container') {
|
||||||
@ -43,9 +49,12 @@ export class InstanceController {
|
|||||||
this.waMonitor.waInstances[instance.instanceName] = instance;
|
this.waMonitor.waInstances[instance.instanceName] = instance;
|
||||||
this.waMonitor.delInstanceTime(instance.instanceName);
|
this.waMonitor.delInstanceTime(instance.instanceName);
|
||||||
|
|
||||||
const hash = await this.authService.generateHash({
|
const hash = await this.authService.generateHash(
|
||||||
instanceName: instance.instanceName,
|
{
|
||||||
});
|
instanceName: instance.instanceName,
|
||||||
|
},
|
||||||
|
token,
|
||||||
|
);
|
||||||
|
|
||||||
let getEvents: string[];
|
let getEvents: string[];
|
||||||
|
|
||||||
@ -78,9 +87,12 @@ export class InstanceController {
|
|||||||
this.waMonitor.waInstances[instance.instanceName] = instance;
|
this.waMonitor.waInstances[instance.instanceName] = instance;
|
||||||
this.waMonitor.delInstanceTime(instance.instanceName);
|
this.waMonitor.delInstanceTime(instance.instanceName);
|
||||||
|
|
||||||
const hash = await this.authService.generateHash({
|
const hash = await this.authService.generateHash(
|
||||||
instanceName: instance.instanceName,
|
{
|
||||||
});
|
instanceName: instance.instanceName,
|
||||||
|
},
|
||||||
|
token,
|
||||||
|
);
|
||||||
|
|
||||||
let getEvents: string[];
|
let getEvents: string[];
|
||||||
|
|
||||||
|
@ -3,4 +3,5 @@ export class InstanceDto {
|
|||||||
webhook?: string;
|
webhook?: string;
|
||||||
events?: string[];
|
events?: string[];
|
||||||
qrcode?: boolean;
|
qrcode?: boolean;
|
||||||
|
token?: string;
|
||||||
}
|
}
|
||||||
|
@ -56,14 +56,14 @@ export class AuthService {
|
|||||||
return { jwt: token };
|
return { jwt: token };
|
||||||
}
|
}
|
||||||
|
|
||||||
private async apikey(instance: InstanceDto) {
|
private async apikey(instance: InstanceDto, token?: string) {
|
||||||
const apikey = v4().toUpperCase();
|
const apikey = token ? token : v4().toUpperCase();
|
||||||
|
|
||||||
const auth = await this.repository.auth.create({ apikey }, instance.instanceName);
|
const auth = await this.repository.auth.create({ apikey }, instance.instanceName);
|
||||||
|
|
||||||
if (auth['error']) {
|
if (auth['error']) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
localError: AuthService.name + '.jwt',
|
localError: AuthService.name + '.apikey',
|
||||||
error: auth['error'],
|
error: auth['error'],
|
||||||
});
|
});
|
||||||
throw new BadRequestException('Authentication error', auth['error']?.toString());
|
throw new BadRequestException('Authentication error', auth['error']?.toString());
|
||||||
@ -72,9 +72,11 @@ export class AuthService {
|
|||||||
return { apikey };
|
return { apikey };
|
||||||
}
|
}
|
||||||
|
|
||||||
public async generateHash(instance: InstanceDto) {
|
public async generateHash(instance: InstanceDto, token?: string) {
|
||||||
const options = this.configService.get<Auth>('AUTHENTICATION');
|
const options = this.configService.get<Auth>('AUTHENTICATION');
|
||||||
return (await this[options.TYPE](instance)) as { jwt: string } | { apikey: string };
|
return (await this[options.TYPE](instance, token)) as
|
||||||
|
| { jwt: string }
|
||||||
|
| { apikey: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
public async refreshToken({ oldToken }: OldToken) {
|
public async refreshToken({ oldToken }: OldToken) {
|
||||||
|
Loading…
Reference in New Issue
Block a user