static withAadApplicationCertificateAuthentication()

in packages/azure-kusto-data/src/connectionBuilder.ts [45:78]


    static withAadApplicationCertificateAuthentication(
        connectionString: string,
        aadAppId: string,
        applicationCertificatePrivateKey?: string,
        authorityId?: string,
        applicationCertificateSendX5c?: boolean,
        applicationCertificatePrivatePath?: string,
    ): KustoConnectionStringBuilder {
        if (aadAppId.trim().length === 0) throw new Error("Invalid app id");
        const kcsb = new KustoConnectionStringBuilder(connectionString);
        if (!applicationCertificatePrivatePath) {
            if (!applicationCertificatePrivateKey) {
                throw new Error("withAadApplicationCertificateAuthentication should specify either a cert key or a path");
            }

            if (applicationCertificatePrivateKey.trim().length === 0) throw new Error("Invalid certificate key");
            kcsb.applicationCertificatePrivateKey = applicationCertificatePrivateKey;
        } else {
            if (applicationCertificatePrivateKey) {
                throw new Error("withAadApplicationCertificateAuthentication should specify either a cert key or a path");
            }

            kcsb.applicationCertificatePath = applicationCertificatePrivatePath;
        }

        kcsb.aadFederatedSecurity = true;
        kcsb.applicationClientId = aadAppId;
        kcsb.applicationCertificateSendX5c = applicationCertificateSendX5c;
        if (authorityId) {
            kcsb.authorityId = authorityId;
        }

        return kcsb;
    }