Skip to content

Commit e6223e0

Browse files
Add instructions to enable SSO
1 parent 881aefd commit e6223e0

12 files changed

Lines changed: 106 additions & 14 deletions

File tree

gen-ai/Assistants/bot-in-a-box/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,48 @@ After running the deployment template, you may also run the application locally
8585
- Send "clear" to delete the current thread;
8686
- Send "logout" to sign out when SSO is enabled;
8787
88+
## Enabling SSO
89+
90+
You can enable Single-Sign-On for your bot so that it identifies the user and keeps a token in context, that can later be used to retreive personal information like their name/job title, as well as for Microsoft Graph API calls.
91+
92+
To enable SSO, follow the steps below. Please note that you should be an `Entra ID Application Developer` and a `Contributor` in the resource group in order to perform the following actions. You can also perform these steps in the portal if you prefer.
93+
94+
- Load the required configurations. Hint: If you just deployed using Azure Developer CLI, you can run `azd env get-values` to retrieve these variables.
95+
```sh
96+
TENANT_ID=$(az account show --query tenantId -o tsv)
97+
APP_REGISTRATION_NAME=[choose app registration display name]
98+
AZURE_RESOURCE_GROUP_NAME=...
99+
BOT_NAME=...
100+
```
101+
102+
- Create an App Registration and retrieve its ID and Client ID.
103+
```sh
104+
APP=$(az ad app create --display-name $APP_REGISTRATION_NAME --web-redirect-uris https://token.botframework.com/.auth/web/redirect)
105+
APP_ID=$(echo $APP | jq -r .id)
106+
CLIENT_ID=$(echo $APP | jq -r .appId)
107+
```
108+
- Create a client secret for the newly created app
109+
```sh
110+
SECRET=$(az ad app credential reset --id $APP_ID)
111+
CLIENT_SECRET=$(echo $SECRET | jq -r .password)
112+
```
113+
114+
- Create an SSO configuration for your bot, passing in the App Registration details
115+
```sh
116+
az bot authsetting create --resource-group $AZURE_RESOURCE_GROUP_NAME --name $BOT_NAME --setting-name default --client-id $CLIENT_ID --client-secret $CLIENT_SECRET --parameters TenantId=$TENANT_ID --service aadv2 --provider-scope-string User.Read
117+
```
118+
119+
- Configure the App Service to use the SSO configuration.
120+
```sh
121+
az webapp config appsettings set -g $AZURE_RESOURCE_GROUP_NAME -n $APP_NAME --settings SSO_ENABLED=true SSO_CONFIG_NAME=default
122+
```
123+
124+
- Clear sensitive variables from terminal
125+
```sh
126+
SECRET=
127+
CLIENT_SECRET=
128+
```
129+
88130
### Enabling Web Chat
89131

90132
To deploy a Web Chat version of your app:

gen-ai/Assistants/bot-in-a-box/infra/main.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,4 @@ output AOAI_NAME string = m_openai.outputs.openaiName
142142
output AOAI_API_ENDPOINT string = m_openai.outputs.openaiEndpoint
143143
output APP_NAME string = m_app.outputs.appName
144144
output APP_HOSTNAME string = m_app.outputs.hostName
145+
output BOT_NAME string = m_bot.outputs.name

gen-ai/Assistants/bot-in-a-box/infra/modules/botservice.bicep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ resource botservice 'Microsoft.BotService/botServices@2022-09-15' = {
2727
}
2828

2929
}
30+
31+
output name string = botservice.name

gen-ai/semantic-kernel-bot-in-a-box/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,48 @@ To create a custom plugin:
109109
110110
And you're done! Redeploy your app and Semantic Kernel will now use your plugin whenever the user's questions call for it.
111111
112+
## Enabling SSO
113+
114+
You can enable Single-Sign-On for your bot so that it identifies the user and keeps a token in context, that can later be used to retreive personal information like their name/job title, as well as for Microsoft Graph API calls.
115+
116+
To enable SSO, follow the steps below. Please note that you should be an `Entra ID Application Developer` and a `Contributor` in the resource group in order to perform the following actions. You can also perform these steps in the portal if you prefer.
117+
118+
- Load the required configurations. Hint: If you just deployed using Azure Developer CLI, you can run `azd env get-values` to retrieve these variables.
119+
```sh
120+
TENANT_ID=$(az account show --query tenantId -o tsv)
121+
APP_REGISTRATION_NAME=[choose app registration display name]
122+
AZURE_RESOURCE_GROUP_NAME=...
123+
BOT_NAME=...
124+
```
125+
126+
- Create an App Registration and retrieve its ID and Client ID.
127+
```sh
128+
APP=$(az ad app create --display-name $APP_REGISTRATION_NAME --web-redirect-uris https://token.botframework.com/.auth/web/redirect)
129+
APP_ID=$(echo $APP | jq -r .id)
130+
CLIENT_ID=$(echo $APP | jq -r .appId)
131+
```
132+
- Create a client secret for the newly created app
133+
```sh
134+
SECRET=$(az ad app credential reset --id $APP_ID)
135+
CLIENT_SECRET=$(echo $SECRET | jq -r .password)
136+
```
137+
138+
- Create an SSO configuration for your bot, passing in the App Registration details
139+
```sh
140+
az bot authsetting create --resource-group $AZURE_RESOURCE_GROUP_NAME --name $BOT_NAME --setting-name default --client-id $CLIENT_ID --client-secret $CLIENT_SECRET --parameters TenantId=$TENANT_ID --service aadv2 --provider-scope-string User.Read
141+
```
142+
143+
- Configure the App Service to use the SSO configuration.
144+
```sh
145+
az webapp config appsettings set -g $AZURE_RESOURCE_GROUP_NAME -n $APP_NAME --settings SSO_ENABLED=true SSO_CONFIG_NAME=default
146+
```
147+
148+
- Clear sensitive variables from terminal
149+
```sh
150+
SECRET=
151+
CLIENT_SECRET=
152+
```
153+
112154
## Enabling Web Chat
113155

114156
To deploy a Web Chat version of your app:

gen-ai/semantic-kernel-bot-in-a-box/infra/main.bicep

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,6 @@ output AZURE_SEARCH_ENDPOINT string = deploySearch ? m_search.outputs.searchEndp
206206
output AZURE_SEARCH_NAME string = deploySearch ? m_search.outputs.searchName : ''
207207
output AZURE_RESOURCE_GROUP_ID string = resourceGroup.id
208208
output AZURE_RESOURCE_GROUP_NAME string = resourceGroup.name
209+
output APP_NAME string = m_app.outputs.appName
210+
output APP_HOSTNAME string = m_app.outputs.hostName
211+
output BOT_NAME string = m_bot.outputs.name

gen-ai/semantic-kernel-bot-in-a-box/infra/modules/appservice.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,5 @@ resource appService 'Microsoft.Web/sites@2022-09-01' = {
217217
}
218218
}
219219

220+
output appName string = appService.name
220221
output hostName string = appService.properties.defaultHostName

gen-ai/semantic-kernel-bot-in-a-box/infra/modules/botservice.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ resource botservice 'Microsoft.BotService/botServices@2022-09-15' = {
2828

2929
}
3030

31+
output name string = botservice.name
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[*.cs]
2-
dotnet_diagnostic.SKEXP0011.severity = none
2+
dotnet_diagnostic.SKEXP0010.severity = none
33
dotnet_diagnostic.SKEXP0060.severity = none
44
dotnet_diagnostic.SKEXP0061.severity = none

gen-ai/semantic-kernel-bot-in-a-box/src/AdapterWithErrorHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<IBotFram
2626
// Send a message to the user
2727
await turnContext.SendActivityAsync("The bot encountered an error or bug.");
2828
await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code.");
29+
await turnContext.SendActivityAsync(exception.Message);
2930

3031
if (conversationState != null)
3132
{

gen-ai/semantic-kernel-bot-in-a-box/src/Bots/SemanticKernelBot.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using System.Text.Json;
89
using Azure.AI.FormRecognizer.DocumentAnalysis;
910
using Azure.AI.OpenAI;
1011
using Azure.Search.Documents;
@@ -112,23 +113,21 @@ public override async Task<string> ProcessMessage(ConversationData conversationD
112113

113114
if (_useStepwisePlanner)
114115
{
115-
var plannerOptions = new FunctionCallingStepwisePlannerConfig
116+
var plannerOptions = new FunctionCallingStepwisePlannerOptions
116117
{
117118
MaxTokens = 128000,
118119
};
119120

120121
var planner = new FunctionCallingStepwisePlanner(plannerOptions);
121122
string prompt = FormatConversationHistory(conversationData);
122123
var result = await planner.ExecuteAsync(kernel, prompt);
124+
await turnContext.SendActivityAsync(JsonSerializer.Serialize(result));
123125

124126
return result.FinalAnswer;
125127
}
126128
else
127129
{
128-
var plannerOptions = new HandlebarsPlannerOptions
129-
{
130-
MaxTokens = 128000,
131-
};
130+
var plannerOptions = new HandlebarsPlannerOptions();
132131

133132
var planner = new HandlebarsPlanner(plannerOptions);
134133
string prompt = FormatConversationHistory(conversationData);

0 commit comments

Comments
 (0)