Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port: [#4019] Addded sample for FIC Echo Bot #432

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Samples are designed to illustrate functionality you'll need to implement to bui
|42|Scale out | Demonstrates how you can build your own state solution from the ground up that supports scaled out deployment with ETag based optimistic locking. |[.NET Core][cs#42] | |[Python][py#42]|[Java][java#42]
|44|Basic custom prompts | Demonstrates how to implement your own _basic_ prompts to ask the user for information. |[.NET Core][cs#44]|[JavaScript][js#44]|[Python][py#44]|[Java][java#44]
|47|Inspection middleware | Demonstrates how to use middleware to allow the Bot Framework Emulator to debug traffic into and out of the bot in addition to looking at the current state of the bot. | [.NET Core][cs#47] | [JavaScript][js#47] |[Python][py#47]|[Java][java#47]
|49| Proxy echo bot | Demonstrates how to configure the bot to use it behind a corporative proxy. | | [JavaScript][js#49] ||
sw-joelmut marked this conversation as resolved.
Show resolved Hide resolved
|70|Styling webchat | This sample shows how to create a web page with custom Web Chat component.| | [ECMAScript 6][es#70] |

### Authentication samples
Expand All @@ -77,7 +78,7 @@ Samples are designed to illustrate functionality you'll need to implement to bui
|46|Teams authentication | Demonstrates how to use authentication for a bot running in Microsoft Teams. | [.NET Core](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-teams-authentication/csharp) | [JavaScript](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-conversation-sso-quickstart/js) |[Python](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-teams-authentication/python)|[Java](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-teams-authentication/java)
|84|Certificate authentication | Demonstrates how to use Certificates to authenticate the bot | [.NET Core][cs#84] |[JavaScript][js#84] | |
|85|Subject name/issuer authentication | Demonstrates how to use the subject name/issuer authentication in a bot | [.NET Core][cs#85] | [JavaScript][js#85] | |
|86|Federated Credentials authentication | Demonstrates how to use the FIC in a bot authentication | [.NET Core][cs#86] | | |
|86|Federated Credentials authentication | Demonstrates how to use the FIC in a bot authentication | [.NET Core][cs#86] | [JavaScript][js#86] | |

### Custom question answering samples

Expand All @@ -97,7 +98,7 @@ Samples are designed to illustrate functionality you'll need to implement to bui
|52|Messaging extensions - auth and config | A Messaging Extension that has a configuration page, accepts search requests and returns results after the user has signed in.|[.NET Core](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-search-auth-config/csharp)|[JavaScript](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-search-sso-config/nodejs) | |
|53|Messaging extensions - action preview | Demonstrates how to create a Preview and Edit flow for a Messaging Extension.|[.NET Core](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-action-preview/csharp)|[JavaScript](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-action-preview/nodejs) |[Python](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-action-preview/python) |[Java](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-action-preview/java)
|54|Task module | Demonstrates how to retrieve a Task Module, and values from cards in the Task Module, for a Messaging Extension.|[.NET Core](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-task-module/csharp)|[JavaScript](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-task-module/nodejs) |[Python](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-task-module/python) |[Java](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-task-module/java)
|55|Link unfurling | A Messaging Extension that performs link unfurling.|[.NET Core](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-link-unfurling/csharp))|[JavaScript](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-link-unfurling/nodejs) |[Python](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-link-unfurling/python) |[Java](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-link-unfurling/java)
|55|Link unfurling | A Messaging Extension that performs link unfurling.|[.NET Core](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-link-unfurling/csharp)|[JavaScript](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-link-unfurling/nodejs) |[Python](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-link-unfurling/python) |[Java](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/msgext-link-unfurling/java)
|56|File upload | Demonstrates how to obtain file consent, and upload files to Teams from a bot. Also, how to receive a file sent to a bot.|[.NET Core](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-file-upload/csharp)|[JavaScript](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-file-upload/nodejs) |[Python](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-file-upload/python) |[Java](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-file-upload/java)
|57|Conversation bot | Demonstrates various features of bots on Teams: message all members in a Team or Channel, @mention a user from a bot, update previously sent messages, etc. |[.NET Core](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-conversation/csharp)|[JavaScript](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-conversation/nodejs) |[Python](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-conversation/python) |[Java](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-conversation/java)
|58|Start new thread in a channel | Demonstrates creating a new thread in a channel. |[.NET Core](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-initiate-thread-in-channel/csharp)|[JavaScript](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-initiate-thread-in-channel/nodejs) |[Python](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-initiate-thread-in-channel/python) |[Java](https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-initiate-thread-in-channel/java)
Expand Down Expand Up @@ -136,6 +137,7 @@ A [collection of **experimental** samples](./experimental) exist, intended to pr
[cs#43]:samples/csharp_dotnetcore/43.complex-dialog
[cs#44]:samples/csharp_dotnetcore/44.prompt-users-for-input
[cs#45]:samples/csharp_dotnetcore/45.state-management
[cs#47]:samples/csharp_dotnetcore/47.inspection
[cs#48]:samples/csharp_dotnetcore/48.customQABot-all-features
[cs#60]:samples/csharp_dotnetcore/60.slack-adapter
[cs#61]:samples/csharp_dotnetcore/61.facebook-adapter
Expand Down Expand Up @@ -187,11 +189,13 @@ A [collection of **experimental** samples](./experimental) exist, intended to pr
[js#45]:samples/javascript_nodejs/45.state-management
[js#47]:samples/javascript_nodejs/47.inspection
[js#48]:samples/javascript_nodejs/48.customQABot-all-features
[js#49]:samples/javascript_nodejs/49.echo-proxy-bot
[js#80]:samples/javascript_nodejs/80.skills-simple-bot-to-bot
[js#81]:samples/javascript_nodejs/81.skills-skilldialog
[js#82]:samples/javascript_nodejs/82.skills-sso-cloudadapter
[js#84]:samples/javascript_nodejs/84.bot-authentication-certificate
[js#85]:samples/javascript_nodejs/85.bot-authentication-sni
[js#86]:samples/javascript_nodejs/86.bot-authentication-fic

[py#1]:samples/python/01.console-echo
[py#2]:samples/python/02.echo-bot
Expand Down
4 changes: 4 additions & 0 deletions samples/javascript_nodejs/86.bot-authentication-fic/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MicrosoftAppType=
MicrosoftAppId=
MicrosoftAppClientId=
MicrosoftAppTenantId=
15 changes: 15 additions & 0 deletions samples/javascript_nodejs/86.bot-authentication-fic/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable */
module.exports = {
"extends": "standard",
"rules": {
"semi": [2, "always"],
"indent": [2, 4],
"no-return-await": 0,
"space-before-function-paren": [2, {
"named": "never",
"anonymous": "never",
"asyncArrow": "always"
}],
"template-curly-spacing": [2, "always"]
}
};
82 changes: 82 additions & 0 deletions samples/javascript_nodejs/86.bot-authentication-fic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Authentication Bot using Federation Identity Certificate (FIC)

Bot Framework v4 bot authentication using Federation Identity Certificate (FIC). Currently, FIC feature is supported for Microsoft tenants only.

This bot has been created using [Bot Framework](https://dev.botframework.com/), is shows how to use the bot authencation capabilities of Azure Bot Service. In this sample, we use federated identity certificate configuration to create the Bot Framework Authentication.

## Prerequisites

- [Node.js](https://nodejs.org) version 18 or higher

```bash
# determine node version
node --version
```

- [Bot Framework SDK](https://github.com/microsoft/botbuilder-dotnet/releases) version 4.23.1 onwards

## To try this sample

- In a terminal, navigate to `samples/javascript_nodejs/86.bot-authentication-fic`

```bash
cd samples/javascript_nodejs/86.bot-authentication-fic
```

- Install modules

```bash
npm install
```

- Create an user assigned managed identity.

- Record the client ID of the managed identity and add the same to .env file.

- Create Azure App and Bot

- Create App Registration
- This can be either Single or Multi tenant.
- Record the Application ID.
- Add the Federation Identity Certificate (FIC) to the App Registration.
- To create trust using the FIC, we need to link the managed identity to the App Registration.
- Click on the add credential under Federated Credential
- On the Add a credential page, select the Federated credential scenario as "Customer Managed Keys".
- Select the managed identity that you created in the previous step.
- Enter name for the credential and click on Add.
- Create an Azure Bot in the desired resource group. Use the App Registration from the previous step.

- Add the User managed identity created in previous step to the Azure App Service under Configuration -> Identity -> User Assigned Managed Identity.

- Set .env variables

- MicrosoftAppType: {SingTenant | MultiTenant}

- MicrosoftAppId: {appId}

- MicrosoftAppTenantId: {tenantId}

- MicrosoftAppClientId: {clientId of managed identity}

- Start the bot

```bash
npm start
```

## Deploy the bot to Azure

To learn more about deploying a bot to Azure, see [Deploy your bot to Azure](https://aka.ms/azuredeployment) for a complete list of deployment instructions.

## Further reading

- [Bot Framework Documentation](https://docs.botframework.com)
- [Bot Basics](https://docs.microsoft.com/azure/bot-service/bot-builder-basics?view=azure-bot-service-4.0)
- [Activity processing](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-activity-processing?view=azure-bot-service-4.0)
- [Azure Bot Service Introduction](https://docs.microsoft.com/azure/bot-service/bot-service-overview-introduction?view=azure-bot-service-4.0)
- [Azure Bot Service Documentation](https://docs.microsoft.com/azure/bot-service/?view=azure-bot-service-4.0)
- [.NET Core CLI tools](https://docs.microsoft.com/en-us/dotnet/core/tools/?tabs=netcore2x)
- [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest)
- [Azure Portal](https://portal.azure.com)
- [Language Understanding using LUIS](https://docs.microsoft.com/en-us/azure/cognitive-services/luis/)
- [Channels and Bot Connector Service](https://docs.microsoft.com/en-us/azure/bot-service/bot-concepts?view=azure-bot-service-4.0)
32 changes: 32 additions & 0 deletions samples/javascript_nodejs/86.bot-authentication-fic/bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const { ActivityHandler, MessageFactory } = require('botbuilder');

class EchoBot extends ActivityHandler {
constructor() {
super();
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
this.onMessage(async (context, next) => {
const replyText = `Echo: ${ context.activity.text }`;
const message = MessageFactory.text(replyText, replyText);
await context.sendActivity(message);
// By calling next() you ensure that the next BotHandler is run.
await next();
});

this.onMembersAdded(async (context, next) => {
const membersAdded = context.activity.membersAdded;
const welcomeText = 'Hello and welcome to Echo Bot Using Federated Identity Credentials !!';
for (let cnt = 0; cnt < membersAdded.length; ++cnt) {
if (membersAdded[cnt].id !== context.activity.recipient.id) {
await context.sendActivity(MessageFactory.text(welcomeText, welcomeText));
}
}
// By calling next() you ensure that the next BotHandler is run.
await next();
});
}
}

module.exports.EchoBot = EchoBot;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[config]
command = ./deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash

# ----------------------
# KUDU Deployment Script
# Version: 1.0.17
# ----------------------

# Helpers
# -------

exitWithMessageOnError () {
if [ ! $? -eq 0 ]; then
echo "An error has occurred during web site deployment."
echo $1
exit 1
fi
}

# Prerequisites
# -------------

# Verify node.js installed
hash node 2>/dev/null
exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment."

# Setup
# -----

SCRIPT_DIR="${BASH_SOURCE[0]%\\*}"
SCRIPT_DIR="${SCRIPT_DIR%/*}"
ARTIFACTS=$SCRIPT_DIR/../artifacts
KUDU_SYNC_CMD=${KUDU_SYNC_CMD//\"}

if [[ ! -n "$DEPLOYMENT_SOURCE" ]]; then
DEPLOYMENT_SOURCE=$SCRIPT_DIR
fi

if [[ ! -n "$NEXT_MANIFEST_PATH" ]]; then
NEXT_MANIFEST_PATH=$ARTIFACTS/manifest

if [[ ! -n "$PREVIOUS_MANIFEST_PATH" ]]; then
PREVIOUS_MANIFEST_PATH=$NEXT_MANIFEST_PATH
fi
fi

if [[ ! -n "$DEPLOYMENT_TARGET" ]]; then
DEPLOYMENT_TARGET=$ARTIFACTS/wwwroot
else
KUDU_SERVICE=true
fi

if [[ ! -n "$KUDU_SYNC_CMD" ]]; then
# Install kudu sync
echo Installing Kudu Sync
npm install kudusync -g --silent
exitWithMessageOnError "npm failed"

if [[ ! -n "$KUDU_SERVICE" ]]; then
# In case we are running locally this is the correct location of kuduSync
KUDU_SYNC_CMD=kuduSync
else
# In case we are running on kudu service this is the correct location of kuduSync
KUDU_SYNC_CMD=$APPDATA/npm/node_modules/kuduSync/bin/kuduSync
fi
fi

# Node Helpers
# ------------

selectNodeVersion () {
NPM_CMD=npm
NODE_EXE=node
}

##################################################################################################################################
# Deployment
# ----------

echo Handling node.js deployment.

# 1. KuduSync
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
"$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
exitWithMessageOnError "Kudu Sync failed"
fi

# 2. Select node version
selectNodeVersion

# 3. Install npm packages
if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
cd "$DEPLOYMENT_TARGET"
echo "Running $NPM_CMD install --production"
eval $NPM_CMD install --production
exitWithMessageOnError "npm failed"
cd - > /dev/null
fi

##################################################################################################################################
echo "Finished successfully."
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[config]
command = deploy.cmd
Loading
Loading