fix(core.gbapp): Admin protected again, additional checks and adjustments.
This commit is contained in:
parent
f5e0835cc3
commit
efea36f1cc
10 changed files with 3544 additions and 786 deletions
4248
package-lock.json
generated
4248
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -86,6 +86,7 @@
|
|||
"request-promise-native": "1.0.8",
|
||||
"rimraf": "3.0.0",
|
||||
"scanf": "1.1.1",
|
||||
"sequelize": "5.21.5",
|
||||
"sequelize-typescript": "1.1.0",
|
||||
"shx": "0.3.2",
|
||||
"simple-git": "1.129.0",
|
||||
|
|
|
@ -126,20 +126,20 @@ export class AdminDialog extends IGBDialog {
|
|||
const prompt = Messages[locale].authenticate;
|
||||
|
||||
return await step.prompt('textPrompt', prompt);
|
||||
// },
|
||||
// async step => {
|
||||
// const locale = step.context.activity.locale;
|
||||
// const sensitive = step.result;
|
||||
},
|
||||
async step => {
|
||||
const locale = step.context.activity.locale;
|
||||
const sensitive = step.result;
|
||||
|
||||
// if (sensitive === GBConfigService.get('ADMIN_PASS')) {
|
||||
// await step.context.sendActivity(Messages[locale].welcome);
|
||||
if (sensitive === GBConfigService.get('ADMIN_PASS')) {
|
||||
await step.context.sendActivity(Messages[locale].welcome);
|
||||
|
||||
// return await step.prompt('textPrompt', Messages[locale].which_task);
|
||||
// } else {
|
||||
// await step.context.sendActivity(Messages[locale].wrong_password);
|
||||
return await step.prompt('textPrompt', Messages[locale].which_task);
|
||||
} else {
|
||||
await step.context.sendActivity(Messages[locale].wrong_password);
|
||||
|
||||
// return await step.endDialog();
|
||||
// }
|
||||
return await step.endDialog();
|
||||
}
|
||||
},
|
||||
async step => {
|
||||
const locale: string = step.context.activity.locale;
|
||||
|
@ -198,7 +198,7 @@ export class AdminDialog extends IGBDialog {
|
|||
} else {
|
||||
await step.context.sendActivity(Messages[locale].finished_working);
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
await step.context.sendActivity(error.message);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ export class GuaribasAdmin extends Model<GuaribasAdmin> {
|
|||
@Column
|
||||
public key: string;
|
||||
|
||||
@Column(DataType.STRING(1024))
|
||||
@Column(DataType.STRING(2048))
|
||||
public value: string;
|
||||
|
||||
@Column
|
||||
|
|
|
@ -176,7 +176,7 @@ export class GBAdminService implements IGBAdminService {
|
|||
instance.authenticatorClientSecret,
|
||||
resource,
|
||||
async (err, res) => {
|
||||
if (err !== undefined) {
|
||||
if (err !== null) {
|
||||
reject(err);
|
||||
} else {
|
||||
const token = res as TokenResponse;
|
||||
|
|
|
@ -520,8 +520,8 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
|||
luisKey: nlpKey,
|
||||
msaAppId: appId,
|
||||
msaAppPassword: appPassword,
|
||||
enabledChannels: ['webchat'], // , "skype", "facebook"],
|
||||
configuredChannels: ['webchat'] // , "skype", "facebook"]
|
||||
enabledChannels: ['webchat', "skype"],//, "facebook"],
|
||||
configuredChannels: ['webchat' , "skype"]//, "facebook"]
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -604,6 +604,30 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
|||
});
|
||||
}
|
||||
|
||||
public async createApplicationSecret(token: string, appId: string) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
let client = MicrosoftGraph.Client.init({
|
||||
authProvider: done => {
|
||||
done(null, token);
|
||||
}
|
||||
});
|
||||
const body = {
|
||||
passwordCredential: {
|
||||
displayName: "General Bots Generated"
|
||||
}
|
||||
};
|
||||
|
||||
client.api(`/applications/${appId}/addPassword`).post(body, (err, res) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
}
|
||||
else {
|
||||
resolve(res.secretText);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private async registerProviders(subscriptionId, baseUrl, accessToken) {
|
||||
const query = `subscriptions/${subscriptionId}/providers/${this.provider}/register?api-version=2018-02-01`;
|
||||
const requestUrl = urlJoin(baseUrl, query);
|
||||
|
|
|
@ -62,7 +62,7 @@ export class WelcomeDialog extends IGBDialog {
|
|||
return step.replaceDialog(GBServer.globals.entryPointDialog);
|
||||
}
|
||||
|
||||
const user = await min.userProfile.get(context, {});
|
||||
const user = await min.userProfile.get(step.context, {});
|
||||
const locale = step.context.activity.locale;
|
||||
|
||||
if (!user.once) {
|
||||
|
|
|
@ -311,8 +311,7 @@ STORAGE_SYNC=true
|
|||
let instance = await GuaribasInstance.findOne(options);
|
||||
// tslint:disable-next-line:prefer-object-spread
|
||||
instance = Object.assign(instance, fullInstance);
|
||||
let ret = await instance.save();
|
||||
return ret;
|
||||
return await instance.save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -166,27 +166,29 @@ export class GBDeployer {
|
|||
public async deployBlankBot(botId: string) {
|
||||
let instance = await this.importer.createBotInstance(botId);
|
||||
|
||||
const username = GBConfigService.get('CLOUD_USERNAME');
|
||||
const password = GBConfigService.get('CLOUD_PASSWORD');
|
||||
const accessToken = await GBAdminService.getADALTokenFromUsername(username, password);
|
||||
const accessToken = await GBServer.globals.minBoot.adminService
|
||||
.acquireElevatedToken(GBServer.globals.bootInstance.instanceId);
|
||||
|
||||
const service = new AzureDeployerService(this);
|
||||
let application = await service.createApplication(accessToken, botId);
|
||||
|
||||
instance.marketplaceId = (application as any).appId;
|
||||
instance.marketplacePassword = (application as any).passwordCredentials[0];
|
||||
instance.marketplacePassword = await service.createApplicationSecret(
|
||||
accessToken, (application as any).id);
|
||||
instance.adminPass = GBAdminService.getRndPassword();
|
||||
instance.title = botId;
|
||||
|
||||
|
||||
await this.core.saveInstance(instance);
|
||||
|
||||
return this.deployBotFull(instance, GBServer.globals.publicAddress);
|
||||
return await this.deployBotFull(instance, GBServer.globals.publicAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploys a bot to the storage.
|
||||
*/
|
||||
|
||||
public async deployBotFull(instance: IGBInstance, publicAddress: string): Promise<void> {
|
||||
public async deployBotFull(instance: IGBInstance, publicAddress: string): Promise<IGBInstance> {
|
||||
|
||||
const service = new AzureDeployerService(this);
|
||||
const username = GBConfigService.get('CLOUD_USERNAME');
|
||||
|
@ -242,7 +244,7 @@ export class GBDeployer {
|
|||
|
||||
await GBServer.globals.minService.mountBot(instance);
|
||||
}
|
||||
await this.core.saveInstance(instance);
|
||||
return await this.core.saveInstance(instance);
|
||||
|
||||
}
|
||||
|
||||
|
@ -514,7 +516,7 @@ export class GBDeployer {
|
|||
}
|
||||
|
||||
folder = Path.join(e, 'dist');
|
||||
if (!Fs.existsSync()) {
|
||||
if (!Fs.existsSync()) {
|
||||
GBLog.info(`Compiling ${e}...`);
|
||||
|
||||
try {
|
||||
|
|
|
@ -49,7 +49,7 @@ export class GBWhatsappPackage implements IGBPackage {
|
|||
public loadBot(min: GBMinInstance): void {
|
||||
// Only loads engine if it is defined on services.json.
|
||||
|
||||
if (min.instance.whatsappBotKey !== undefined && min.instance.whatsappBotKey !== null ) {
|
||||
if (min.instance.whatsappServiceKey !== null ) {
|
||||
min.whatsAppDirectLine = new WhatsappDirectLine(
|
||||
min.botId,
|
||||
min.instance.whatsappBotKey,
|
||||
|
|
Loading…
Add table
Reference in a new issue