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

microsoft / botbuilder-js / 12431963409

20 Dec 2024 01:05PM CUT coverage: 84.624% (-0.001%) from 84.625%
12431963409

Pull #4823

github

web-flow
Merge 04876b140 into 3b8fcab21
Pull Request #4823: fix: [#4684] ESLint issues in botbuilder-testing

8185 of 10821 branches covered (75.64%)

Branch coverage included in aggregate %.

15 of 15 new or added lines in 1 file covered. (100.0%)

20512 of 23090 relevant lines covered (88.83%)

7391.54 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';
2✔
9
import { ServiceClientCredentials } from '@azure/core-http';
10
import { ServiceClientCredentialsFactory } from './serviceClientCredentialsFactory';
11
import { AuthenticationConstants } from './authenticationConstants';
2✔
12
import { GovernmentConstants } from './governmentConstants';
2✔
13

14
/**
15
 * An implementation of ServiceClientCredentialsFactory that generates MsalAppCredentials
16
 */
17
export class MsalServiceClientCredentialsFactory implements ServiceClientCredentialsFactory {
2✔
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(appId: string, private readonly clientApplication: ConfidentialClientApplication) {
×
28
        this.appId = appId;
×
29
    }
30

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

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

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

58
        if (!(await this.isValidAppId(appId))) {
×
59
            throw new Error('Invalid appId.');
×
60
        }
61

62
        const normalizedEndpoint = loginEndpoint.toLowerCase();
×
63

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

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

82
        return new MsalAppCredentials(this.clientApplication, appId, loginEndpoint, audience);
×
83
    }
84
}
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