-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into hond/error-msg
- Loading branch information
Showing
273 changed files
with
5,229 additions
and
2,398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lTests/Microsoft.Bot.Builder.FunctionalTests/Microsoft.Bot.Builder.FunctionalTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...lTests/Skills/SimpleBotToBot/EchoSkillBot/Authentication/AllowedCallersClaimsValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using Microsoft.Bot.Connector.Authentication; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Microsoft.BotBuilderSamples.EchoSkillBot31.Authentication | ||
{ | ||
/// <summary> | ||
/// Sample claims validator that loads an allowed list from configuration if present | ||
/// and checks that requests are coming from allowed parent bots. | ||
/// </summary> | ||
public class AllowedCallersClaimsValidator : ClaimsValidator | ||
{ | ||
private const string ConfigKey = "AllowedCallers"; | ||
private readonly List<string> _allowedCallers; | ||
|
||
public AllowedCallersClaimsValidator(IConfiguration config) | ||
{ | ||
if (config == null) | ||
{ | ||
throw new ArgumentNullException(nameof(config)); | ||
} | ||
|
||
// AllowedCallers is the setting in appsettings.json file | ||
// that consists of the list of parent bot ids that are allowed to access the skill | ||
// to add a new parent bot simply go to the AllowedCallers and add | ||
// the parent bot's microsoft app id to the list | ||
var section = config.GetSection(ConfigKey); | ||
var appsList = section.Get<string[]>(); | ||
_allowedCallers = appsList != null ? new List<string>(appsList) : null; | ||
} | ||
|
||
public override Task ValidateClaimsAsync(IList<Claim> claims) | ||
{ | ||
// if _allowedCallers is null we allow all calls | ||
if (_allowedCallers != null && SkillValidation.IsSkillClaim(claims)) | ||
{ | ||
// Check that the appId claim in the skill request is in the list of skills configured for this bot. | ||
var appId = JwtTokenValidation.GetAppIdFromClaims(claims); | ||
if (!_allowedCallers.Contains(appId)) | ||
{ | ||
throw new UnauthorizedAccessException($"Received a request from a bot with an app ID of \"{appId}\". To enable requests from this caller, add the app ID to your configuration file."); | ||
} | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
FunctionalTests/Skills/SimpleBotToBot/EchoSkillBot/Bots/EchoBot.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Schema; | ||
|
||
namespace Microsoft.BotBuilderSamples.EchoSkillBot31.Bots | ||
{ | ||
public class EchoBot : ActivityHandler | ||
{ | ||
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken) | ||
{ | ||
if (turnContext.Activity.Text.Contains("end") || turnContext.Activity.Text.Contains("stop")) | ||
{ | ||
// Send End of conversation at the end. | ||
await turnContext.SendActivityAsync(MessageFactory.Text($"ending conversation from the skill..."), cancellationToken); | ||
var endOfConversation = Activity.CreateEndOfConversationActivity(); | ||
endOfConversation.Code = EndOfConversationCodes.CompletedSuccessfully; | ||
await turnContext.SendActivityAsync(endOfConversation, cancellationToken); | ||
} | ||
else | ||
{ | ||
await turnContext.SendActivityAsync(MessageFactory.Text($"Echo (dotnet core 3.1) : {turnContext.Activity.Text}"), cancellationToken); | ||
await turnContext.SendActivityAsync(MessageFactory.Text("Say \"end\" or \"stop\" and I'll end the conversation and back to the parent."), cancellationToken); | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
FunctionalTests/Skills/SimpleBotToBot/EchoSkillBot/Controllers/BotController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Bot.Builder; | ||
using Microsoft.Bot.Builder.Integration.AspNet.Core; | ||
|
||
namespace Microsoft.BotBuilderSamples.EchoSkillBot31.Controllers | ||
{ | ||
// This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot | ||
// implementation at runtime. Multiple different IBot implementations running at different endpoints can be | ||
// achieved by specifying a more specific type for the bot constructor argument. | ||
[Route("api/messages")] | ||
[ApiController] | ||
public class BotController : ControllerBase | ||
{ | ||
private readonly IBotFrameworkHttpAdapter _adapter; | ||
private readonly IBot _bot; | ||
|
||
public BotController(IBotFrameworkHttpAdapter adapter, IBot bot) | ||
{ | ||
_adapter = adapter; | ||
_bot = bot; | ||
} | ||
|
||
[HttpPost] | ||
public async Task PostAsync() | ||
{ | ||
await _adapter.ProcessAsync(Request, Response, _bot); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
FunctionalTests/Skills/SimpleBotToBot/EchoSkillBot/EchoSkillBot.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
<AssemblyName>Microsoft.BotBuilderSamples.EchoSkillBot31</AssemblyName> | ||
<RootNamespace>Microsoft.BotBuilderSamples.EchoSkillBot31</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\libraries\integration\Microsoft.Bot.Builder.Integration.AspNet.Core\Microsoft.Bot.Builder.Integration.AspNet.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
23 changes: 23 additions & 0 deletions
23
FunctionalTests/Skills/SimpleBotToBot/EchoSkillBot/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Microsoft.BotBuilderSamples.EchoSkillBot31 | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
FunctionalTests/Skills/SimpleBotToBot/EchoSkillBot/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:39783/", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": false, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"EchoSkillBot31": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:5001;http://localhost:5000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.