From ef762d1bc88ddafa860753b14eda6a865f3efe98 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 22 Jan 2025 11:23:30 -0800 Subject: [PATCH] Remove the fallback logic for authorization check. Stick to the production URL --- .../Microsoft.Azure.Agent/ChatSession.cs | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs index 064d73b..82b94cc 100644 --- a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs +++ b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs @@ -11,8 +11,7 @@ namespace Microsoft.Azure.Agent; internal class ChatSession : IDisposable { - private const string PROD_ACCESS_URL = "https://copilotweb.production.portalrp.azure.com/api/access?api-version=2024-09-01"; - private const string TEST_ACCESS_URL = "https://copilotweb.canary.production.portalrp.azure.com/api/access?api-version=2024-09-01"; + private const string ACCESS_URL = "https://copilotweb.production.portalrp.azure.com/api/access?api-version=2024-09-01"; private const string DL_TOKEN_URL = "https://copilotweb.production.portalrp.azure.com/api/conversations/start?api-version=2024-11-15"; internal bool UserAuthorized { get; private set; } @@ -141,13 +140,11 @@ private async Task SetupNewChat(IStatusContext context, CancellationToke private async Task CheckAuthorizationAsync(CancellationToken cancellationToken) { - HttpResponseMessage response = await SendRequestAsync(PROD_ACCESS_URL); - if (response.StatusCode is not System.Net.HttpStatusCode.OK) - { - // We fall back to the test endpoint when the prod endpoint is unavailable. - Telemetry.Trace(AzTrace.Exception($"Prod access endpoint unavailable. HTTP status: {response.StatusCode}. Fall back to canary endpoint.")); - response = await SendRequestAsync(TEST_ACCESS_URL); - } + HttpRequestMessage request = new(HttpMethod.Get, ACCESS_URL); + request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken.Token); + + HttpResponseMessage response = await _httpClient.SendAsync(request, cancellationToken); await response.EnsureSuccessStatusCodeForTokenRequest("Failed to check Copilot authorization."); using Stream stream = await response.Content.ReadAsStreamAsync(cancellationToken); @@ -160,14 +157,6 @@ private async Task CheckAuthorizationAsync(CancellationToken cancellationToken) Telemetry.Trace(AzTrace.Exception(message)); throw new TokenRequestException(message) { UserUnauthorized = true }; } - - async Task SendRequestAsync(string url) - { - HttpRequestMessage request = new(HttpMethod.Get, url); - request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken.Token); - return await _httpClient.SendAsync(request, cancellationToken); - } } private async Task GetInitialDLTokenAsync(CancellationToken cancellationToken)