Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the fallback logic for authorization check and stick to the production URL #334

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions shell/agents/Microsoft.Azure.Agent/ChatSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -141,13 +140,11 @@ private async Task<string> 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);
Expand All @@ -160,14 +157,6 @@ private async Task CheckAuthorizationAsync(CancellationToken cancellationToken)
Telemetry.Trace(AzTrace.Exception(message));
throw new TokenRequestException(message) { UserUnauthorized = true };
}

async Task<HttpResponseMessage> 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)
Expand Down
Loading