@@ -29,7 +29,7 @@ export class BotFrameworkHttpClient {
2929 */
3030 private static readonly appCredentialMapCache : Map < string , MicrosoftAppCredentials > = new Map < string , MicrosoftAppCredentials > ( ) ;
3131
32- constructor ( private readonly credentialProvider : ICredentialProvider , private readonly channelService ?: string ) {
32+ public constructor ( private readonly credentialProvider : ICredentialProvider , private readonly channelService ?: string ) {
3333 if ( ! this . credentialProvider ) {
3434 throw new Error ( 'BotFrameworkHttpClient(): missing credentialProvider' ) ;
3535 }
@@ -96,6 +96,19 @@ export class BotFrameworkHttpClient {
9696 }
9797 }
9898
99+ protected async buildCredentials ( appId : string , oAuthScope ?: string ) : Promise < MicrosoftAppCredentials > {
100+ const appPassword = await this . credentialProvider . getAppPassword ( appId ) ;
101+ let appCredentials ;
102+ if ( JwtTokenValidation . isGovernment ( this . channelService ) ) {
103+ appCredentials = new MicrosoftAppCredentials ( appId , appPassword , this . channelService , oAuthScope ) ;
104+ appCredentials . oAuthEndpoint = GovernmentConstants . ToChannelFromBotLoginUrl ;
105+ appCredentials . oAuthScope = GovernmentConstants . ToChannelFromBotOAuthScope ;
106+ } else {
107+ appCredentials = new MicrosoftAppCredentials ( appId , appPassword , this . channelService , oAuthScope ) ;
108+ }
109+ return appCredentials ;
110+ }
111+
99112 /**
100113 * Gets the application credentials. App Credentials are cached so as to ensure we are not refreshing
101114 * token every time.
@@ -114,14 +127,8 @@ export class BotFrameworkHttpClient {
114127 return appCredentials ;
115128 }
116129
117- const appPassword = await this . credentialProvider . getAppPassword ( appId ) ;
118- if ( JwtTokenValidation . isGovernment ( this . channelService ) ) {
119- appCredentials = new MicrosoftAppCredentials ( appId , appPassword , this . channelService , oAuthScope ) ;
120- appCredentials . oAuthEndpoint = GovernmentConstants . ToChannelFromBotLoginUrl ;
121- appCredentials . oAuthScope = GovernmentConstants . ToChannelFromBotOAuthScope ;
122- } else {
123- appCredentials = new MicrosoftAppCredentials ( appId , appPassword , this . channelService , oAuthScope ) ;
124- }
130+ // Credentials not found in cache, build them
131+ appCredentials = await this . buildCredentials ( appId , oAuthScope ) ;
125132
126133 // Cache the credentials for later use
127134 BotFrameworkHttpClient . appCredentialMapCache . set ( cacheKey , appCredentials ) ;
0 commit comments