@microsoft/agents-hosting
Version:
Microsoft 365 Agents SDK for JavaScript
108 lines • 4.33 kB
JavaScript
;
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadPrevAuthConfigFromEnv = exports.loadAuthConfigFromEnv = void 0;
/**
* Loads the authentication configuration from environment variables.
*
* @example
* ```
* tenantId=your-tenant-id
* clientId=your-client-id
* clientSecret=your-client-secret
*
* certPemFile=your-cert-pem-file
* certKeyFile=your-cert-key-file
*
* FICClientId=your-FIC-client-id
*
* connectionName=your-connection-name
* authority=your-authority-endpoint
* ```
* @remarks
* - `clientId` is required
* @returns The authentication configuration.
* @throws Will throw an error if clientId is not provided in production.
*/
const loadAuthConfigFromEnv = (cnxName) => {
var _a, _b, _c;
if (cnxName === undefined) {
const authority = (_a = process.env.authorityEndpoint) !== null && _a !== void 0 ? _a : 'https://login.microsoftonline.com';
if (process.env.clientId === undefined && process.env.NODE_ENV === 'production') {
throw new Error('ClientId required in production');
}
return {
tenantId: process.env.tenantId,
clientId: process.env.clientId,
clientSecret: process.env.clientSecret,
certPemFile: process.env.certPemFile,
certKeyFile: process.env.certKeyFile,
connectionName: process.env.connectionName,
FICClientId: process.env.FICClientId,
authority,
issuers: [
'https://api.botframework.com',
`https://sts.windows.net/${process.env.tenantId}/`,
`${authority}/${process.env.tenantId}/v2.0`
],
};
}
else {
const authority = (_b = process.env[`${cnxName}_authorityEndpoint`]) !== null && _b !== void 0 ? _b : 'https://login.microsoftonline.com';
return {
tenantId: process.env[`${cnxName}_tenantId`],
clientId: (_c = process.env[`${cnxName}_clientId`]) !== null && _c !== void 0 ? _c : (() => { throw new Error(`ClientId not found for connection: ${cnxName}`); })(),
clientSecret: process.env[`${cnxName}_clientSecret`],
certPemFile: process.env[`${cnxName}_certPemFile`],
certKeyFile: process.env[`${cnxName}_certKeyFile`],
connectionName: process.env[`${cnxName}_connectionName`],
FICClientId: process.env[`${cnxName}_FICClientId`],
authority,
issuers: [
'https://api.botframework.com',
`https://sts.windows.net/${process.env[`${cnxName}_tenantId`]}/`,
`${authority}/${process.env[`${cnxName}_tenantId`]}/v2.0`
]
};
}
};
exports.loadAuthConfigFromEnv = loadAuthConfigFromEnv;
/**
* Loads the agent authentication configuration from previous version environment variables.
*
* @example
* ```
* MicrosoftAppId=your-client-id
* MicrosoftAppPassword=your-client-secret
* MicrosoftAppTenantId=your-tenant-id
* ```
* @returns The agent authentication configuration.
* @throws Will throw an error if MicrosoftAppId is not provided in production.
*/
const loadPrevAuthConfigFromEnv = () => {
var _a;
if (process.env.MicrosoftAppId === undefined && process.env.NODE_ENV === 'production') {
throw new Error('ClientId required in production');
}
const authority = (_a = process.env.authorityEndpoint) !== null && _a !== void 0 ? _a : 'https://login.microsoftonline.com';
return {
tenantId: process.env.MicrosoftAppTenantId,
clientId: process.env.MicrosoftAppId,
clientSecret: process.env.MicrosoftAppPassword,
certPemFile: process.env.certPemFile,
certKeyFile: process.env.certKeyFile,
connectionName: process.env.connectionName,
FICClientId: process.env.MicrosoftAppClientId,
authority,
issuers: [
'https://api.botframework.com',
`https://sts.windows.net/${process.env.MicrosoftAppTenantId}/`,
`${authority}/${process.env.MicrosoftAppTenantId}/v2.0`
]
};
};
exports.loadPrevAuthConfigFromEnv = loadPrevAuthConfigFromEnv;
//# sourceMappingURL=authConfiguration.js.map