Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Create store
const store = redux.createStore(conversation.store,
redux.applyMiddleware(
// our custom Redux middleware
lowerCase,
// and a popular piece of Redux middleware from npm
createLogger()
));
// Create the authenticator (for inbound activities) and the credentials (for outbound activities)
const botCredentials = {
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
};
const authenticator = new SimpleCredentialProvider(botCredentials.appId, botCredentials.appPassword);
const credentials = new MicrosoftAppCredentials(botCredentials.appId, botCredentials.appPassword);;
// Redux provides a simple pub-sub model that we can use to help organize our application logic in a decoupled way
server.post('/api/messages', (req, res) => {
console.log('processReq:', req.body);
let activity = req.body;
// authenticate request
JwtTokenValidation.assertValidActivity(activity, req.headers.authorization, authenticator).then(() => {
// dispatch the inbound activity to redux
store.dispatch({ type: activity.type, activity: activity });
res.send(202);
constructor(settings?: Partial) {
super();
this.settings = { appId: '', appPassword: '', ...settings };
// If settings.certificateThumbprint & settings.certificatePrivateKey are provided,
// use CertificateAppCredentials.
if (this.settings.certificateThumbprint && this.settings.certificatePrivateKey) {
this.credentials = new CertificateAppCredentials(this.settings.appId, settings.certificateThumbprint, settings.certificatePrivateKey, this.settings.channelAuthTenant);
this.credentialsProvider = new SimpleCredentialProvider(this.credentials.appId, '');
} else {
this.credentials = new MicrosoftAppCredentials(this.settings.appId, this.settings.appPassword || '', this.settings.channelAuthTenant);
this.credentialsProvider = new SimpleCredentialProvider(this.credentials.appId, this.settings.appPassword || '');
}
this.isEmulatingOAuthCards = false;
// If no channelService or openIdMetadata values were passed in the settings, check the process' Environment Variables for values.
// These values may be set when a bot is provisioned on Azure and if so are required for the bot to properly work in Public Azure or a National Cloud.
this.settings.channelService = this.settings.channelService || process.env[AuthenticationConstants.ChannelService];
this.settings.openIdMetadata = this.settings.openIdMetadata || process.env[AuthenticationConstants.BotOpenIdMetadataKey];
this.authConfiguration = this.settings.authConfig || new AuthenticationConfiguration();
if (this.settings.openIdMetadata) {
ChannelValidation.OpenIdMetadataEndpoint = this.settings.openIdMetadata;
GovernmentChannelValidation.OpenIdMetadataEndpoint = this.settings.openIdMetadata;
}
private async getAppCredentials(appId: string, oAuthScope?: string): Promise {
if (!appId) {
return new MicrosoftAppCredentials('', '');
}
const cacheKey = `${ appId }${ oAuthScope }`;
let appCredentials = BotFrameworkHttpClient.appCredentialMapCache.get(cacheKey);
if (appCredentials) {
return appCredentials;
}
const appPassword = await this.credentialProvider.getAppPassword(appId);
if (JwtTokenValidation.isGovernment(this.channelService)) {
appCredentials = new MicrosoftAppCredentials(appId, appPassword, this.channelService);
appCredentials.oAuthEndpoint = GovernmentConstants.ToChannelFromBotLoginUrl;
appCredentials.oAuthScope = GovernmentConstants.ToChannelFromBotOAuthScope;
} else {
appCredentials = new MicrosoftAppCredentials(appId, appPassword, this.channelService);
appCredentials.oAuthScope = !oAuthScope ? AuthenticationConstants.ToChannelFromBotOAuthScope : oAuthScope;
}
// Cache the credentials for later use
BotFrameworkHttpClient.appCredentialMapCache.set(cacheKey, appCredentials);
return appCredentials;
}
}
return new MicrosoftAppCredentials('', '');
}
const cacheKey = `${ appId }${ oAuthScope }`;
let appCredentials = BotFrameworkHttpClient.appCredentialMapCache.get(cacheKey);
if (appCredentials) {
return appCredentials;
}
const appPassword = await this.credentialProvider.getAppPassword(appId);
if (JwtTokenValidation.isGovernment(this.channelService)) {
appCredentials = new MicrosoftAppCredentials(appId, appPassword, this.channelService);
appCredentials.oAuthEndpoint = GovernmentConstants.ToChannelFromBotLoginUrl;
appCredentials.oAuthScope = GovernmentConstants.ToChannelFromBotOAuthScope;
} else {
appCredentials = new MicrosoftAppCredentials(appId, appPassword, this.channelService);
appCredentials.oAuthScope = !oAuthScope ? AuthenticationConstants.ToChannelFromBotOAuthScope : oAuthScope;
}
// Cache the credentials for later use
BotFrameworkHttpClient.appCredentialMapCache.set(cacheKey, appCredentials);
return appCredentials;
}
}
if (botSettings.cosmosDb === undefined) {
throw new Error();
}
const cosmosDbStorageSettings: CosmosDbStorageSettings = {
authKey: botSettings.cosmosDb.authKey,
collectionId: botSettings.cosmosDb.collectionId,
databaseId: botSettings.cosmosDb.databaseId,
serviceEndpoint: botSettings.cosmosDb.cosmosDBEndpoint
};
const storage: CosmosDbStorage = new CosmosDbStorage(cosmosDbStorageSettings);
const userState: UserState = new UserState(storage);
const conversationState: ConversationState = new ConversationState(storage);
const appCredentials: MicrosoftAppCredentials = new MicrosoftAppCredentials(
botSettings.microsoftAppId || '',
botSettings.microsoftAppPassword || ''
);
const adapter: DefaultAdapter = new DefaultAdapter(
botSettings,
adapterSettings,
telemetryClient,
userState,
conversationState
);
// const webSocketEnabledHttpAdapter: webSocketEnabledHttpAdapter = (botsettings, adapter))
let bot: DialogBot<dialog>;
try {
const botServices: BotServices = new BotServices(botSettings, telemetryClient);
</dialog>
private async getAppCredentials(appId: string, oAuthScope?: string): Promise {
if (!appId) {
return new MicrosoftAppCredentials('', '');
}
const cacheKey = `${ appId }${ oAuthScope }`;
let appCredentials = BotFrameworkHttpClient.appCredentialMapCache.get(cacheKey);
if (appCredentials) {
return appCredentials;
}
const appPassword = await this.credentialProvider.getAppPassword(appId);
if (JwtTokenValidation.isGovernment(this.channelService)) {
appCredentials = new MicrosoftAppCredentials(appId, appPassword, this.channelService);
appCredentials.oAuthEndpoint = GovernmentConstants.ToChannelFromBotLoginUrl;
appCredentials.oAuthScope = GovernmentConstants.ToChannelFromBotOAuthScope;
} else {
appCredentials = new MicrosoftAppCredentials(appId, appPassword, this.channelService);
appCredentials.oAuthScope = !oAuthScope ? AuthenticationConstants.ToChannelFromBotOAuthScope : oAuthScope;
constructor(settings) {
super();
this.settings = Object.assign({ appId: '', appPassword: '' }, settings);
this.credentials = new botframework_connector_1.MicrosoftAppCredentials(this.settings.appId, this.settings.appPassword || '');
this.credentialsProvider = new botframework_connector_1.SimpleCredentialProvider(this.credentials.appId, this.credentials.appPassword);
this.isEmulatingOAuthCards = false;
}
/**
constructor(settings) {
this.nextId = 0;
settings = settings === undefined ? { appId: '', appPassword: '' } : settings;
this.credentials = new botframework_connector_1.MicrosoftAppCredentials(settings.appId || '', settings.appPassword || '');
this.credentialsProvider = new botframework_connector_1.SimpleCredentialProvider(this.credentials.appId, this.credentials.appPassword);
this.onReceive = undefined;
}
/**
constructor({appId: appId, password: password, fb_verify_token: fb_verify_token, fb_password: fb_password, fb_access_token: fb_access_token}){
super({
verify_token: fb_verify_token,
app_secret: fb_password,
access_token: fb_access_token
});
this.credentials = new botframework_connector.MicrosoftAppCredentials(appId, password);
this.credentialsProvider = new botframework_connector.SimpleCredentialProvider(appId, password);
this.tokenApiClient = new botframework_connector.TokenApiClient(this.credentials, { baseUri: OAUTH_ENDPOINT, userAgent: exports.USER_AGENT });;
}