Skip to content

Commit aabb05b

Browse files
authored
Allow custom tenant for Entra ID auth (#10658)
* Allow custom tenant for Entra ID auth * Remove-Item is no longer needed for load test results
1 parent 2389fc7 commit aabb05b

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/NuGetGallery.Services/Authentication/Providers/AzureActiveDirectoryV2/AzureActiveDirectoryV2Authenticator.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -42,7 +42,6 @@ public static class AuthenticationType
4242

4343
public static readonly string DefaultAuthenticationType = "AzureActiveDirectoryV2";
4444
public static readonly string PersonalMSATenant = "9188040d-6c67-4c5b-b112-36a304b66dad";
45-
public static readonly string V2CommonTenant = "common";
4645
public static readonly string Authority = "https://login.microsoftonline.com/{0}/v2.0";
4746

4847
private static string _callbackPath = "users/account/authenticate/return";
@@ -280,4 +279,4 @@ private Task AuthorizationCodeReceived(AuthorizationCodeReceivedNotification con
280279
return Task.CompletedTask;
281280
}
282281
}
283-
}
282+
}

src/NuGetGallery.Services/Authentication/Providers/AzureActiveDirectoryV2/AzureActiveDirectoryV2AuthenticatorConfiguration.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -11,6 +11,7 @@ namespace NuGetGallery.Authentication.Providers.AzureActiveDirectoryV2
1111
{
1212
public class AzureActiveDirectoryV2AuthenticatorConfiguration : AuthenticatorConfiguration
1313
{
14+
public string TenantId { get; set; }
1415
public string ClientId { get; set; }
1516

1617
public AzureActiveDirectoryV2AuthenticatorConfiguration()
@@ -30,17 +31,24 @@ public override void ApplyToOwinSecurityOptions(AuthenticationOptions options)
3031
// the auth flow.
3132
openIdOptions.AuthenticationMode = AuthenticationMode.Passive;
3233

33-
// Make sure ClientId is configured
34-
if (String.IsNullOrEmpty(ClientId))
34+
if (string.IsNullOrEmpty(TenantId))
3535
{
36-
throw new ConfigurationErrorsException(String.Format(
36+
throw new ConfigurationErrorsException(string.Format(
37+
CultureInfo.CurrentCulture,
38+
ServicesStrings.MissingRequiredConfigurationValue,
39+
"Auth.CommonAuth.TenantId"));
40+
}
41+
42+
if (string.IsNullOrEmpty(ClientId))
43+
{
44+
throw new ConfigurationErrorsException(string.Format(
3745
CultureInfo.CurrentCulture,
3846
ServicesStrings.MissingRequiredConfigurationValue,
3947
"Auth.CommonAuth.ClientId"));
4048
}
4149

4250
openIdOptions.ClientId = ClientId;
43-
openIdOptions.Authority = String.Format(CultureInfo.InvariantCulture, AzureActiveDirectoryV2Authenticator.Authority, AzureActiveDirectoryV2Authenticator.V2CommonTenant);
51+
openIdOptions.Authority = string.Format(CultureInfo.InvariantCulture, AzureActiveDirectoryV2Authenticator.Authority, TenantId);
4452
}
4553
}
4654
}

src/NuGetGallery/Web.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<add key="Auth.MicrosoftAccount.ClientId" value=""/>
9797
<add key="Auth.MicrosoftAccount.ClientSecret" value=""/>
9898
<add key="Auth.AzureActiveDirectoryV2.Enabled" value="false"/>
99+
<add key="Auth.AzureActiveDirectoryV2.TenantId" value="common"/>
99100
<add key="Auth.AzureActiveDirectoryV2.ClientId" value=""/>
100101
<add key="Auth.AzureActiveDirectory.Enabled" value="false"/>
101102
<add key="Auth.AzureActiveDirectory.ClientId" value=""/>

tests/Scripts/RunGalleryFunctionalTestCategory.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ $webUITestResults = "$parentDir/NuGetGallery.$TestCategory.WebUITests.trx"
2020
# Clean previous test results
2121
Remove-Item $functionalTestsResults -ErrorAction Ignore
2222
Remove-Item $webUITestResults -ErrorAction Ignore
23-
Remove-Item $loadTestResults -ErrorAction Ignore
2423

2524
# Run functional tests
2625
$fullTestCategory = "$($testCategory)Tests"
@@ -35,7 +34,7 @@ if ($LASTEXITCODE -ne 0) {
3534
# Run web UI tests
3635
$webTestsDirectory = "$parentDir\NuGetGallery.WebUITests.$TestCategory\bin\$Configuration\net472"
3736

38-
if (Test-Path $webTestsDirectory -PathType Container) {
37+
if (Test-Path $webTestsDirectory -PathType Container) {
3938
& $vsTest "$webTestsDirectory\NuGetGallery.WebUITests.$TestCategory.dll" "/Settings:$parentDir\Local.testsettings" "/Logger:trx;LogFileName=$webUITestResults"
4039
if ($LASTEXITCODE -ne 0) {
4140
$exitCode = 1

0 commit comments

Comments
 (0)