diff --git a/src/dotnet/APIView/APIViewWeb/Controllers/PullRequestController.cs b/src/dotnet/APIView/APIViewWeb/Controllers/PullRequestController.cs index 0b5d9dea013..92cfcb836de 100644 --- a/src/dotnet/APIView/APIViewWeb/Controllers/PullRequestController.cs +++ b/src/dotnet/APIView/APIViewWeb/Controllers/PullRequestController.cs @@ -26,7 +26,6 @@ public class PullRequestController : Controller private readonly IReviewManager _reviewManager; private readonly IAPIRevisionsManager _apiRevisionsManager; private readonly IConfiguration _configuration; - private readonly IOpenSourceRequestManager _openSourceManager; private readonly TelemetryClient _telemetryClient; private HashSet _allowedListBotAccounts = new HashSet(); @@ -34,14 +33,13 @@ public class PullRequestController : Controller public PullRequestController(ICodeFileManager codeFileManager, IPullRequestManager pullRequestManager, IAPIRevisionsManager apiRevisionsManager, IReviewManager reviewManager, - IConfiguration configuration, IOpenSourceRequestManager openSourceRequestManager, TelemetryClient telemetryClient) + IConfiguration configuration, TelemetryClient telemetryClient) { _codeFileManager = codeFileManager; _pullRequestManager = pullRequestManager; _reviewManager = reviewManager; _apiRevisionsManager = apiRevisionsManager; _configuration = configuration; - _openSourceManager = openSourceRequestManager; _telemetryClient = telemetryClient; var botAllowedList = _configuration["allowedList-bot-github-accounts"]; @@ -139,10 +137,6 @@ private async Task DetectAPIChanges(string buildId, } pullRequestModel.Commits.Add(commitSha); - //Check if PR owner is part of Azure//Microsoft org in GitHub - await ManagerHelpers.AssertPullRequestCreatorPermission(prModel: pullRequestModel, allowedListBotAccounts: _allowedListBotAccounts, - openSourceManager: _openSourceManager, telemetryClient: _telemetryClient); - try { diff --git a/src/dotnet/APIView/APIViewWeb/Helpers/ManagerHelpers.cs b/src/dotnet/APIView/APIViewWeb/Helpers/ManagerHelpers.cs index 55a839b2638..19275e021f1 100644 --- a/src/dotnet/APIView/APIViewWeb/Helpers/ManagerHelpers.cs +++ b/src/dotnet/APIView/APIViewWeb/Helpers/ManagerHelpers.cs @@ -69,22 +69,6 @@ public static void AssertAPIRevisionDeletion(APIRevisionListItemModel apiRevisio } } - public static async Task AssertPullRequestCreatorPermission( - PullRequestModel prModel, HashSet allowedListBotAccounts, IOpenSourceRequestManager openSourceManager, - TelemetryClient telemetryClient) - { - // White list bot accounts to create API reviews from PR automatically - if (!allowedListBotAccounts.Contains(prModel.CreatedBy)) - { - var isAuthorized = await openSourceManager.IsAuthorizedUser(prModel.CreatedBy); - if (!isAuthorized) - { - telemetryClient.TrackTrace($"API change detection permission failed for user {prModel.CreatedBy}. API review is only created if PR author is an internal user."); - throw new AuthorizationFailedException(); - } - } - } - public static string ResolveReviewUrl(PullRequestModel pullRequest, string hostName) { var url = $"https://{hostName}/Assemblies/Review/{pullRequest.ReviewId}"; diff --git a/src/dotnet/APIView/APIViewWeb/Managers/Interfaces/IOpenSourceRequestManager.cs b/src/dotnet/APIView/APIViewWeb/Managers/Interfaces/IOpenSourceRequestManager.cs deleted file mode 100644 index 0f5c57edc83..00000000000 --- a/src/dotnet/APIView/APIViewWeb/Managers/Interfaces/IOpenSourceRequestManager.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Threading.Tasks; -using APIViewWeb.Models; - -namespace APIViewWeb.Managers -{ - public interface IOpenSourceRequestManager - { - public Task GetUserInfo(string githubUserId); - - public Task IsAuthorizedUser(string githubUserId); - } -} diff --git a/src/dotnet/APIView/APIViewWeb/Managers/OpenSourceRequestManager.cs b/src/dotnet/APIView/APIViewWeb/Managers/OpenSourceRequestManager.cs deleted file mode 100644 index d6594200cae..00000000000 --- a/src/dotnet/APIView/APIViewWeb/Managers/OpenSourceRequestManager.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text.Json; -using System.Threading.Tasks; -using System.Web; -using APIViewWeb.Models; -using Azure.Core; -using Azure.Identity; -using Microsoft.ApplicationInsights; -using Microsoft.Extensions.Configuration; -using Newtonsoft.Json; - -namespace APIViewWeb.Managers -{ - public class OpenSourceRequestManager : IOpenSourceRequestManager - { - static readonly string[] scopes = new string[] { "api://2789159d-8d8b-4d13-b90b-ca29c1707afd/.default" }; - private readonly string _aadClientId; - private readonly string _aadClientSecret; - private readonly string _aadTenantId; - private readonly TelemetryClient _telemetryClient; - - public OpenSourceRequestManager(IConfiguration configuration, TelemetryClient telemetryClient) - { - _aadClientId = configuration["opensource-aad-app-id"] ?? ""; - _aadClientSecret = configuration["opensource-aad-client-secret"] ?? ""; - _aadTenantId = configuration["opensource-aad-tenant-id"] ?? ""; - _telemetryClient = telemetryClient; - } - - public async Task GetUserInfo(string githubUserId) - { - int retryCount = 0; - bool authCheckCompleted = false; - while (!authCheckCompleted && retryCount < 3) - { - try - { - retryCount++; - var ossClient = new HttpClient(); - await SetHeaders(ossClient); - var response = await ossClient.GetAsync($"https://repos.opensource.microsoft.com/api/people/links/github/{githubUserId}"); - response.EnsureSuccessStatusCode(); - var userDetailsJson = await response.Content.ReadAsStringAsync(); - return JsonConvert.DeserializeObject(userDetailsJson); - } - catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.NotFound) - { - _telemetryClient.TrackTrace($"GitHub username {githubUserId} is not found"); - authCheckCompleted = true; - } - catch (Exception ex) - { - _telemetryClient.TrackException(ex); - } - - if(!authCheckCompleted && retryCount < 3) - { - await Task.Delay(2000); - _telemetryClient.TrackTrace($"Retrying to check user authorization for user Id {githubUserId}"); - } - } - return null; - } - - public async Task IsAuthorizedUser(string githubUserId) - { - var resp = await GetUserInfo(githubUserId); - if (resp == null) - return false; - // For now we only need to check if user info is available on MS OSS - return true; - } - - private async Task SetHeaders(HttpClient ossClient) - { - var clientCredential = new ClientSecretCredential(_aadTenantId, _aadClientId, _aadClientSecret); - var token = (await clientCredential.GetTokenAsync(new TokenRequestContext(scopes))).Token; - ossClient.DefaultRequestHeaders.Add("content_type", "application/json"); - ossClient.DefaultRequestHeaders.Add("api-version", "2019-10-01"); - ossClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - } - } -} diff --git a/src/dotnet/APIView/APIViewWeb/Models/OpenSourceUserInfo.cs b/src/dotnet/APIView/APIViewWeb/Models/OpenSourceUserInfo.cs deleted file mode 100644 index 2c3b20c4d0b..00000000000 --- a/src/dotnet/APIView/APIViewWeb/Models/OpenSourceUserInfo.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace APIViewWeb.Models -{ - public class OpenSourceUserInfo - { - public GitHubInfo github; - public AadInfo aad; - } - - public class GitHubInfo - { - [JsonProperty("login")] - public string Login { get; set; } - - [JsonProperty("organizations")] - public string[] Orgs; - } - - public class AadInfo - { - [JsonProperty("alias")] - public string Alias { get; set; } - - [JsonProperty("preferredName")] - public string PrefferedName { get; set; } - - [JsonProperty("userPrncipalName")] - public string UserPrnciPalName { get; set; } - - [JsonProperty("emailAddress")] - public string EmailAddress { get; set; } - } -} diff --git a/src/dotnet/APIView/APIViewWeb/Startup.cs b/src/dotnet/APIView/APIViewWeb/Startup.cs index da22971ff91..232a93bfdeb 100644 --- a/src/dotnet/APIView/APIViewWeb/Startup.cs +++ b/src/dotnet/APIView/APIViewWeb/Startup.cs @@ -112,7 +112,6 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(); services.AddSingleton();