Skip to content

Commit f5e84eb

Browse files
author
Tom Laird-McConnell
authored
fix OAuth with emulator and no credentials (#4570)
1 parent 35e6058 commit f5e84eb

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

CSharp/EchoBot/Web.config

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
-->
66
<configuration>
77
<appSettings>
8-
<add key="BotId" value="LoadEchoBot" />
9-
<add key="MicrosoftAppId" value="aeb40bdb-fffe-48e2-8650-921c7de13383" />
10-
<add key="MicrosoftAppPassword" value="hywgFM57]acaZWCLM348=[[" />
8+
<add key="BotId" value="TomDemoBot" />
9+
<add key="MicrosoftAppId" value="76a09a21-e91c-4396-bef6-b3a785c78cad" />
10+
<add key="MicrosoftAppPassword" value="M1tW7XhYe6.O0&amp;-O" />
11+
<!--<add key="BotId" value="YourBotId" />
12+
<add key="MicrosoftAppId" value="" />
13+
<add key="MicrosoftAppPassword" value="" />-->
1114
</appSettings>
1215
<system.web>
1316
<compilation debug="true" targetFramework="4.6.1" />

CSharp/Library/Microsoft.Bot.Builder/ConnectorEx/IConnectorClientFactory.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,30 +114,34 @@ public ConnectorClientFactory(IAddress address, MicrosoftAppCredentials credenti
114114

115115
if (!oauthClients.TryGetValue(key, out oauthClient))
116116
{
117-
if (IsEmulator(this.address) && emulateOAuthCards.Value)
117+
// only create the oauthclient if we have credentials
118+
if (!String.IsNullOrEmpty(credentials?.MicrosoftAppId) && !String.IsNullOrEmpty(credentials?.MicrosoftAppPassword))
118119
{
119-
// for emulator using emulated OAuthCards we should use serviceUri of the emulator
120-
oauthClient = new OAuthClient(this.serviceUri, this.credentials);
121-
}
122-
else
123-
{
124-
if (!string.IsNullOrEmpty(settingsOAuthApiUrl.Value))
120+
if (IsEmulator(this.address) && emulateOAuthCards.Value)
125121
{
126-
oauthClient = new OAuthClient(new Uri(settingsOAuthApiUrl.Value), this.credentials);
122+
// for emulator using emulated OAuthCards we should use serviceUri of the emulator
123+
oauthClient = new OAuthClient(this.serviceUri, this.credentials);
127124
}
128125
else
129126
{
130-
oauthClient = new OAuthClient(this.credentials);
127+
if (!string.IsNullOrEmpty(settingsOAuthApiUrl.Value))
128+
{
129+
oauthClient = new OAuthClient(new Uri(settingsOAuthApiUrl.Value), this.credentials);
130+
}
131+
else
132+
{
133+
oauthClient = new OAuthClient(this.credentials);
134+
}
131135
}
132-
}
133136

134-
if (IsEmulator(this.address))
135-
{
136-
// Send the mode notification (emulated OAuthCards or not) to the emulator
137-
Task.Run(async () => await oauthClient.OAuthApi.SendEmulateOAuthCardsAsync(emulateOAuthCards.Value).ConfigureAwait(false)).Wait();
138-
}
137+
if (IsEmulator(this.address))
138+
{
139+
// Send the mode notification (emulated OAuthCards or not) to the emulator
140+
Task.Run(async () => await oauthClient.OAuthApi.SendEmulateOAuthCardsAsync(emulateOAuthCards.Value).ConfigureAwait(false)).Wait();
141+
}
139142

140-
oauthClients[key] = oauthClient;
143+
oauthClients[key] = oauthClient;
144+
}
141145
}
142146
}
143147

@@ -207,7 +211,7 @@ private static bool GetEmulateOAuthCardsSetting(string key = "EmulateOAuthCards"
207211
// default back to false
208212
result = false;
209213
}
210-
214+
211215
return result;
212216
}
213217
}

0 commit comments

Comments
 (0)