Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit c7f0d13

Browse files
Batta32ryanisgrig
authored andcommitted
[Botskills] Display a warning when the tool found an unrecognized scope (#2658)
* Solution to the issue of unrecognized scopes * Comment the code
1 parent 7ba87f4 commit c7f0d13

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

tools/botskills/src/utils/authenticationUtils.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
IConnectConfiguration,
1414
IOauthConnection,
1515
IScopeManifest,
16-
ISkillManifest } from '../models';
16+
ISkillManifest
17+
} from '../models';
1718
import { ChildProcessUtils, isValidAzVersion } from './';
1819

1920
export class AuthenticationUtils {
@@ -82,16 +83,33 @@ export class AuthenticationUtils {
8283
return this.scopeMap.get(scope) || '';
8384
}
8485

85-
private createScopeManifest(scopes: string[]): IScopeManifest[] {
86+
private createScopeManifest(scopes: string[], logger: ILogger): IScopeManifest[] {
87+
const scopesRecognized: string [] = [];
88+
const scopesNotRecognized: string [] = [];
89+
// Check the scopes that are recognized and set to scopesRecognized
90+
// If it's not recognized, it will be set to scopesNotRecognized
91+
scopes.forEach((scope: string) => {
92+
if (scope.trim().length > 0) {
93+
if (this.scopeMap.has(scope)) {
94+
scopesRecognized.push(scope);
95+
} else {
96+
scopesNotRecognized.push(scope);
97+
}
98+
}
99+
});
100+
// If any of the scopes were not recognized, it will log a warning showing the list of scopes
101+
if (scopesNotRecognized.length > 0) {
102+
logger.warning(`The following scopes were not recognized: ${scopesNotRecognized.join(',')}`);
103+
}
104+
86105
return [{
87106
resourceAppId: '00000003-0000-0000-c000-000000000000',
88-
resourceAccess: scopes.filter((scope: string) => this.scopeMap.has(scope))
89-
.map((scope: string) => {
90-
return {
91-
id: this.getScopeId(scope),
92-
type: 'Scope'
93-
};
94-
})
107+
resourceAccess: scopesRecognized.map((scope: string) => {
108+
return {
109+
id: this.getScopeId(scope),
110+
type: 'Scope'
111+
};
112+
})
95113
}];
96114
}
97115

@@ -188,7 +206,7 @@ export class AuthenticationUtils {
188206

189207
// Remove duplicate scopes
190208
scopes = [...new Set(scopes)];
191-
const scopeManifest: IScopeManifest[] = this.createScopeManifest(scopes);
209+
const scopeManifest: IScopeManifest[] = this.createScopeManifest(scopes, logger);
192210

193211
// get the information of the app
194212
const azureAppShowCommand: string[] = ['az', 'ad', 'app', 'show'];
@@ -262,12 +280,12 @@ export class AuthenticationUtils {
262280
logger.warning(`There was an error while executing the following command:\n\t${currentCommand.join(' ')}\n${err.message}`);
263281
logger.warning(`You must configure one of the following connection types MANUALLY in the Azure Portal:
264282
${manifest.authenticationConnections.map((authConn: IAuthenticationConnection) => authConn.serviceProviderId)
265-
.join(', ')}`);
283+
.join(', ')}`);
266284
logger.warning(`For more information on setting up the authentication configuration manually go to:\n${this.docLink}`);
267285
} else if (manifest.authenticationConnections && manifest.authenticationConnections.length > 0) {
268286
logger.warning(`${err.message} You must configure one of the following connection types MANUALLY in the Azure Portal:
269287
${manifest.authenticationConnections.map((authConn: IAuthenticationConnection) => authConn.serviceProviderId)
270-
.join(', ')}`);
288+
.join(', ')}`);
271289
logger.warning(`For more information on setting up the authentication configuration manually go to:\n${this.docLink}`);
272290
} else {
273291
logger.warning(err.message);

0 commit comments

Comments
 (0)