Skip to content

Commit edd7ded

Browse files
authored
Remove the fallback logic for authorization check and stick to the production URL (#334)
1 parent 4606b3d commit edd7ded

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

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

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

1212
internal class ChatSession : IDisposable
1313
{
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";
14+
private const string ACCESS_URL = "https://copilotweb.production.portalrp.azure.com/api/access?api-version=2024-09-01";
1615
private const string DL_TOKEN_URL = "https://copilotweb.production.portalrp.azure.com/api/conversations/start?api-version=2024-11-15";
1716

1817
internal bool UserAuthorized { get; private set; }
@@ -141,13 +140,11 @@ private async Task<string> SetupNewChat(IStatusContext context, CancellationToke
141140

142141
private async Task CheckAuthorizationAsync(CancellationToken cancellationToken)
143142
{
144-
HttpResponseMessage response = await SendRequestAsync(PROD_ACCESS_URL);
145-
if (response.StatusCode is not System.Net.HttpStatusCode.OK)
146-
{
147-
// We fall back to the test endpoint when the prod endpoint is unavailable.
148-
Telemetry.Trace(AzTrace.Exception($"Prod access endpoint unavailable. HTTP status: {response.StatusCode}. Fall back to canary endpoint."));
149-
response = await SendRequestAsync(TEST_ACCESS_URL);
150-
}
143+
HttpRequestMessage request = new(HttpMethod.Get, ACCESS_URL);
144+
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
145+
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken.Token);
146+
147+
HttpResponseMessage response = await _httpClient.SendAsync(request, cancellationToken);
151148
await response.EnsureSuccessStatusCodeForTokenRequest("Failed to check Copilot authorization.");
152149

153150
using Stream stream = await response.Content.ReadAsStreamAsync(cancellationToken);
@@ -160,14 +157,6 @@ private async Task CheckAuthorizationAsync(CancellationToken cancellationToken)
160157
Telemetry.Trace(AzTrace.Exception(message));
161158
throw new TokenRequestException(message) { UserUnauthorized = true };
162159
}
163-
164-
async Task<HttpResponseMessage> SendRequestAsync(string url)
165-
{
166-
HttpRequestMessage request = new(HttpMethod.Get, url);
167-
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
168-
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken.Token);
169-
return await _httpClient.SendAsync(request, cancellationToken);
170-
}
171160
}
172161

173162
private async Task GetInitialDLTokenAsync(CancellationToken cancellationToken)

0 commit comments

Comments
 (0)