Skip to content

Commit 46cf1e7

Browse files
committed
Use prod access endpoint first and fall back to the test endpoint when it's not available
1 parent 2671579 commit 46cf1e7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

shell/agents/Microsoft.Azure.Agent/ChatSession.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ namespace Microsoft.Azure.Agent;
1111

1212
internal class ChatSession : IDisposable
1313
{
14-
// TODO: production URL not yet working for some regions.
15-
// private const string ACCESS_URL = "https://copilotweb.production.portalrp.azure.com/api/access?api-version=2024-09-01";
16-
private const string ACCESS_URL = "https://copilotweb.canary.production.portalrp.azure.com/api/access?api-version=2024-09-01";
14+
private const string PROD_ACCESS_URL = "https://copilotweb.production.portalrp.azure.com/api/access?api-version=2024-09-01";
15+
private const string TEST_ACCESS_URL = "https://copilotweb.canary.production.portalrp.azure.com/api/access?api-version=2024-09-01";
1716
private const string DL_TOKEN_URL = "https://copilotweb.production.portalrp.azure.com/api/conversations/start?api-version=2024-11-15";
1817
private const string CONVERSATION_URL = "https://directline.botframework.com/v3/directline/conversations";
1918

@@ -141,11 +140,17 @@ private async Task<string> SetupNewChat(IStatusContext context, CancellationToke
141140

142141
private async Task CheckAuthorizationAsync(CancellationToken cancellationToken)
143142
{
144-
HttpRequestMessage request = new(HttpMethod.Get, ACCESS_URL);
143+
HttpRequestMessage request = new(HttpMethod.Get, PROD_ACCESS_URL);
145144
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
146145
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken.Token);
147146

148147
HttpResponseMessage response = await _httpClient.SendAsync(request, cancellationToken);
148+
if (response.StatusCode is System.Net.HttpStatusCode.Forbidden)
149+
{
150+
// We fall back to the test endpoint when the prod endpoint is unavailable.
151+
request.RequestUri = new Uri(TEST_ACCESS_URL, UriKind.RelativeOrAbsolute);
152+
response = await _httpClient.SendAsync(request, cancellationToken);
153+
}
149154
await response.EnsureSuccessStatusCodeForTokenRequest("Failed to check Copilot authorization.");
150155

151156
using Stream stream = await response.Content.ReadAsStreamAsync(cancellationToken);

0 commit comments

Comments
 (0)