Skip to content

Commit

Permalink
fix OAuth with emulator and no credentials (#4570)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Laird-McConnell authored May 6, 2018
1 parent 35e6058 commit f5e84eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
9 changes: 6 additions & 3 deletions CSharp/EchoBot/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
-->
<configuration>
<appSettings>
<add key="BotId" value="LoadEchoBot" />
<add key="MicrosoftAppId" value="aeb40bdb-fffe-48e2-8650-921c7de13383" />
<add key="MicrosoftAppPassword" value="hywgFM57]acaZWCLM348=[[" />
<add key="BotId" value="TomDemoBot" />
<add key="MicrosoftAppId" value="76a09a21-e91c-4396-bef6-b3a785c78cad" />
<add key="MicrosoftAppPassword" value="M1tW7XhYe6.O0&amp;-O" />
<!--<add key="BotId" value="YourBotId" />
<add key="MicrosoftAppId" value="" />
<add key="MicrosoftAppPassword" value="" />-->
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,34 @@ public ConnectorClientFactory(IAddress address, MicrosoftAppCredentials credenti

if (!oauthClients.TryGetValue(key, out oauthClient))
{
if (IsEmulator(this.address) && emulateOAuthCards.Value)
// only create the oauthclient if we have credentials
if (!String.IsNullOrEmpty(credentials?.MicrosoftAppId) && !String.IsNullOrEmpty(credentials?.MicrosoftAppPassword))
{
// for emulator using emulated OAuthCards we should use serviceUri of the emulator
oauthClient = new OAuthClient(this.serviceUri, this.credentials);
}
else
{
if (!string.IsNullOrEmpty(settingsOAuthApiUrl.Value))
if (IsEmulator(this.address) && emulateOAuthCards.Value)
{
oauthClient = new OAuthClient(new Uri(settingsOAuthApiUrl.Value), this.credentials);
// for emulator using emulated OAuthCards we should use serviceUri of the emulator
oauthClient = new OAuthClient(this.serviceUri, this.credentials);
}
else
{
oauthClient = new OAuthClient(this.credentials);
if (!string.IsNullOrEmpty(settingsOAuthApiUrl.Value))
{
oauthClient = new OAuthClient(new Uri(settingsOAuthApiUrl.Value), this.credentials);
}
else
{
oauthClient = new OAuthClient(this.credentials);
}
}
}

if (IsEmulator(this.address))
{
// Send the mode notification (emulated OAuthCards or not) to the emulator
Task.Run(async () => await oauthClient.OAuthApi.SendEmulateOAuthCardsAsync(emulateOAuthCards.Value).ConfigureAwait(false)).Wait();
}
if (IsEmulator(this.address))
{
// Send the mode notification (emulated OAuthCards or not) to the emulator
Task.Run(async () => await oauthClient.OAuthApi.SendEmulateOAuthCardsAsync(emulateOAuthCards.Value).ConfigureAwait(false)).Wait();
}

oauthClients[key] = oauthClient;
oauthClients[key] = oauthClient;
}
}
}

Expand Down Expand Up @@ -207,7 +211,7 @@ private static bool GetEmulateOAuthCardsSetting(string key = "EmulateOAuthCards"
// default back to false
result = false;
}

return result;
}
}
Expand Down

0 comments on commit f5e84eb

Please sign in to comment.