Skip to content

Commit

Permalink
update oauth message ext
Browse files Browse the repository at this point in the history
  • Loading branch information
aacebo committed Jan 18, 2024
1 parent 4165baa commit ff6adda
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Teams.AI;

namespace MessageExtensionAuth
{
public class AdapterWithErrorHandler : CloudAdapter
public class AdapterWithErrorHandler : TeamsAdapter
{
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<CloudAdapter> logger)
: base(auth, logger)
public AdapterWithErrorHandler(IConfiguration configuration, ILogger<TeamsAdapter> logger)
: base(configuration, null, logger)
{
OnTurnError = async (turnContext, exception) =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Teams.AI;

namespace MessageExtensionAuth.Controllers
{
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
private readonly CloudAdapter _adapter;
private readonly TeamsAdapter _adapter;
private readonly IBot _bot;

public BotController(CloudAdapter adapter, IBot bot)
public BotController(TeamsAdapter adapter, IBot bot)
{
_adapter = adapter;
_bot = bot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.21.1" />
<PackageReference Include="Microsoft.Graph" Version="4.54.0" />
<PackageReference Include="Microsoft.Identity.Web.TokenCache" Version="2.16.0" />
<PackageReference Include="Microsoft.Teams.AI" Version="1.0.*-*" />
<PackageReference Include="Microsoft.Teams.AI" Version="1.1.*-*" />
</ItemGroup>

<!-- Exclude Teams Toolkit files from build output, but can still be viewed from Solution Explorer -->
Expand Down
8 changes: 4 additions & 4 deletions dotnet/samples/06.auth.oauth.messageExtension/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
// Create the Cloud Adapter with error handling enabled.
// Note: some classes expect a BotAdapter and some expect a BotFrameworkHttpAdapter, so
// register the same adapter instance for all types.
builder.Services.AddSingleton<CloudAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<CloudAdapter>()!);
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<CloudAdapter>()!);
builder.Services.AddSingleton<TeamsAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<TeamsAdapter>()!);
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<TeamsAdapter>()!);

// Create singleton instances for bot application
builder.Services.AddSingleton<IStorage, MemoryStorage>();
Expand All @@ -43,7 +43,7 @@
builder.Services.AddTransient<IBot>(sp =>
{
IStorage storage = sp.GetService<IStorage>()!;
BotAdapter adapter = sp.GetService<CloudAdapter>()!;
TeamsAdapter adapter = sp.GetService<TeamsAdapter>()!;

AuthenticationOptions<TurnState> options = new();
options.AddAuthentication("graph", new OAuthSettings()
Expand Down

0 comments on commit ff6adda

Please sign in to comment.