• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microsoft / botbuilder-js / 13264809812

11 Feb 2025 02:09PM CUT coverage: 84.524%. Remained the same
13264809812

Pull #4856

github

web-flow
Merge 4e615f951 into 7534989ce
Pull Request #4856: fix: [#4786] Clarify createBotFrameworkAuthenticationFromConfiguration usage in yo templates

8205 of 10860 branches covered (75.55%)

Branch coverage included in aggregate %.

20555 of 23166 relevant lines covered (88.73%)

4123.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.38
/libraries/botframework-connector/src/auth/msalServiceClientCredentialsFactory.ts
1
/**
2
 * @module botframework-connector
3
 */
4
// Copyright (c) Microsoft Corporation.
5
// Licensed under the MIT License.
6

7
import { ConfidentialClientApplication } from '@azure/msal-node';
8
import { MsalAppCredentials } from './msalAppCredentials';
1✔
9
import { ServiceClientCredentials } from '@azure/core-http';
10
import { ServiceClientCredentialsFactory } from './serviceClientCredentialsFactory';
11
import { AuthenticationConstants } from './authenticationConstants';
1✔
12
import { GovernmentConstants } from './governmentConstants';
1✔
13

14
/**
15
 * An implementation of ServiceClientCredentialsFactory that generates MsalAppCredentials
16
 */
17
export class MsalServiceClientCredentialsFactory implements ServiceClientCredentialsFactory {
1✔
18
    private readonly appId: string;
19

20
    /**
21
     * Create an MsalServiceClientCredentialsFactory instance using runtime configuration and an
22
     * `@azure/msal-node` `ConfidentialClientApplication`.
23
     *
24
     * @param appId App ID for validation.
25
     * @param clientApplication An `@azure/msal-node` `ConfidentialClientApplication` instance.
26
     */
27
    constructor(
28
        appId: string,
29
        private readonly clientApplication: ConfidentialClientApplication,
×
30
    ) {
31
        this.appId = appId;
×
32
    }
33

34
    /**
35
     * @inheritdoc
36
     */
37
    async isValidAppId(appId: string): Promise<boolean> {
38
        return appId === this.appId;
×
39
    }
40

41
    /**
42
     * @inheritdoc
43
     */
44
    async isAuthenticationDisabled(): Promise<boolean> {
45
        return !this.appId;
×
46
    }
47

48
    /**
49
     * @inheritdoc
50
     */
51
    async createCredentials(
52
        appId: string,
53
        audience: string,
54
        loginEndpoint: string,
55
        _validateAuthority: boolean,
56
    ): Promise<ServiceClientCredentials> {
57
        if (await this.isAuthenticationDisabled()) {
×
58
            return MsalAppCredentials.Empty;
×
59
        }
60

61
        if (!(await this.isValidAppId(appId))) {
×
62
            throw new Error('Invalid appId.');
×
63
        }
64

65
        const normalizedEndpoint = loginEndpoint.toLowerCase();
×
66

67
        if (normalizedEndpoint.startsWith(AuthenticationConstants.ToChannelFromBotLoginUrlPrefix)) {
×
68
            return new MsalAppCredentials(
×
69
                this.clientApplication,
70
                appId,
71
                undefined,
72
                audience || AuthenticationConstants.ToBotFromChannelTokenIssuer,
×
73
            );
74
        }
75

76
        if (normalizedEndpoint.startsWith(GovernmentConstants.ToChannelFromBotLoginUrlPrefix)) {
×
77
            return new MsalAppCredentials(
×
78
                this.clientApplication,
79
                appId,
80
                undefined,
81
                audience || GovernmentConstants.ToChannelFromBotOAuthScope,
×
82
            );
83
        }
84

85
        return new MsalAppCredentials(this.clientApplication, appId, loginEndpoint, audience);
×
86
    }
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc