Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
Merged
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
29 changes: 25 additions & 4 deletions libraries/Microsoft.Bot.Builder.Dialogs/Prompts/OAuthPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,32 @@ public OAuthPrompt(string dialogId, OAuthPromptSettings settings, PromptValidato
throw new InvalidOperationException("OAuthPrompt.Recognize(): not supported by the current adapter");
}

var token = await adapter.GetUserTokenAsync(turnContext, _settings.ConnectionName, magicCode, cancellationToken).ConfigureAwait(false);
if (token != null)
// Getting the token follows a different flow in Teams. At the signin completion, Teams
// will send the bot an "invoke" activity that contains a "magic" code. This code MUST
// then be used to try fetching the token from Botframework service within some time
// period. We try here. If it succeeds, we return 200 with an empty body. If it fails
// with a retriable error, we return 500. Teams will re-send another invoke in this case.
// If it failes with a non-retriable error, we return 404. Teams will not (still work in
// progress) retry in that case.
try
{
result.Succeeded = true;
result.Value = token;
var token = await adapter.GetUserTokenAsync(turnContext, _settings.ConnectionName, magicCode, cancellationToken).ConfigureAwait(false);

if (token != null)
{
result.Succeeded = true;
result.Value = token;

await turnContext.SendActivityAsync(new Activity { Type = ActivityTypesEx.InvokeResponse }, cancellationToken).ConfigureAwait(false);
}
else
{
await turnContext.SendActivityAsync(new Activity { Type = ActivityTypesEx.InvokeResponse, Value = new InvokeResponse { Status = 404 } }, cancellationToken).ConfigureAwait(false);
}
}
catch
{
await turnContext.SendActivityAsync(new Activity { Type = ActivityTypesEx.InvokeResponse, Value = new InvokeResponse { Status = 500 } }, cancellationToken).ConfigureAwait(false);
}
}
else if (turnContext.Activity.Type == ActivityTypes.Message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ namespace Microsoft.Bot.Builder.Integration.AspNet.Core
/// </summary>
public class BotFrameworkHttpAdapter : BotFrameworkAdapter, IBotFrameworkHttpAdapter
{
public BotFrameworkHttpAdapter(IConfiguration configuration, ILogger<BotFrameworkHttpAdapter> logger = null)
public BotFrameworkHttpAdapter(ICredentialProvider credentialProvider = null, IChannelProvider channelProvider = null, ILogger<BotFrameworkHttpAdapter> logger = null)
: base(credentialProvider ?? new SimpleCredentialProvider(), channelProvider, null, null, null, logger)
{
}

public BotFrameworkHttpAdapter(ICredentialProvider credentialProvider, IChannelProvider channelProvider, HttpClient httpClient, ILogger<BotFrameworkHttpAdapter> logger)
: base(credentialProvider ?? new SimpleCredentialProvider(), channelProvider, null, httpClient, null, logger)
{
}

protected BotFrameworkHttpAdapter(IConfiguration configuration, ILogger<BotFrameworkHttpAdapter> logger = null)
: base(new ConfigurationCredentialProvider(configuration), new ConfigurationChannelProvider(configuration), customHttpClient: null, middleware: null, logger: logger)
{
var openIdEndpoint = configuration.GetSection(AuthenticationConstants.BotOpenIdMetadataKey)?.Value;
Expand All @@ -32,16 +42,6 @@ public BotFrameworkHttpAdapter(IConfiguration configuration, ILogger<BotFramewor
}
}

public BotFrameworkHttpAdapter(ICredentialProvider credentialProvider = null, IChannelProvider channelProvider = null, ILogger<BotFrameworkHttpAdapter> logger = null)
: base(credentialProvider ?? new SimpleCredentialProvider(), channelProvider, null, null, null, logger)
{
}

public BotFrameworkHttpAdapter(ICredentialProvider credentialProvider, IChannelProvider channelProvider, HttpClient httpClient, ILogger<BotFrameworkHttpAdapter> logger)
: base(credentialProvider ?? new SimpleCredentialProvider(), channelProvider, null, httpClient, null, logger)
{
}

public async Task ProcessAsync(HttpRequest httpRequest, HttpResponse httpResponse, IBot bot, CancellationToken cancellationToken = default(CancellationToken))
{
if (httpRequest == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ public static void WriteResponse(HttpResponse response, InvokeResponse invokeRes
}
else
{
response.ContentType = "application/json";
response.StatusCode = invokeResponse.Status;

using (var writer = new StreamWriter(response.Body))
if (invokeResponse.Body != null)
{
using (var jsonWriter = new JsonTextWriter(writer))
response.ContentType = "application/json";

using (var writer = new StreamWriter(response.Body))
{
BotMessageSerializer.Serialize(jsonWriter, invokeResponse.Body);
using (var jsonWriter = new JsonTextWriter(writer))
{
BotMessageSerializer.Serialize(jsonWriter, invokeResponse.Body);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void ConstructorWithConfiguration()
.Build();

// Act
var adapter = new BotFrameworkHttpAdapter(configuration);
var adapter = new MyAdapter(configuration);

// Assert

Expand Down Expand Up @@ -177,6 +177,14 @@ private static Stream CreateStream(Activity activity)
return stream;
}

private class MyAdapter : BotFrameworkHttpAdapter
{
public MyAdapter(IConfiguration configuration)
: base(configuration)
{
}
}

private class InvokeResponseBot : IBot
{
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
Expand Down