File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed
osx/Microsoft.Authentication.Helper.Mac/Source
Microsoft.AzureRepos.Tests Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,23 @@ int main(int argc, const char * argv[]) {
100
100
NSString * redirectUri = [configs objectForKey: @" redirectUri" ];
101
101
NSString * interactive = [configs objectForKey: @" interactive" ];
102
102
103
+ // Because ADAL only supports the v1 endpoints we need to transform any request
104
+ // for the /organizations or /consumers authority to the /common one or else
105
+ // we get errors back from the server.
106
+ NSString *lowerAuthority = [authority lowercaseString ];
107
+ if ([lowerAuthority hasSuffix: @" /organizations" ] || [lowerAuthority hasSuffix: @" /consumers" ])
108
+ {
109
+ NSError *error = nil ;
110
+ NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern: @" /(organizations|consumers)$"
111
+ options: NSRegularExpressionCaseInsensitive
112
+ error: &error];
113
+ NSString * newAuthority = [regex stringByReplacingMatchesInString: authority
114
+ options: 0
115
+ range: NSMakeRange (0 , authority.length)
116
+ withTemplate: @" /common" ];
117
+ authority = newAuthority;
118
+ }
119
+
103
120
// We only perform interactive flows
104
121
if (isTruthy (interactive))
105
122
{
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ public class AzureDevOpsApiTests
21
21
private const string ExpectedLocationServicePath = "_apis/ServiceDefinitions/LocationService2/951917AC-A960-4999-8464-E3F0AA25B381?api-version=1.0" ;
22
22
private const string ExpectedIdentityServicePath = "_apis/token/sessiontokens?api-version=1.0&tokentype=compact" ;
23
23
private const string CommonAuthority = "https://login.microsoftonline.com/common" ;
24
+ private const string OrganizationsAuthority = "https://login.microsoftonline.com/organizations" ;
24
25
25
26
[ Fact ]
26
27
public async Task AzureDevOpsRestApi_GetAuthorityAsync_NullUri_ThrowsException ( )
@@ -169,13 +170,15 @@ public async Task AzureDevOpsRestApi_GetAuthorityAsync_VssResourceTenantMultiple
169
170
}
170
171
171
172
[ Fact ]
172
- public async Task AzureDevOpsRestApi_GetAuthorityAsync_VssResourceTenantMsa_ReturnsCommonAuthority ( )
173
+ public async Task AzureDevOpsRestApi_GetAuthorityAsync_VssResourceTenantMsa_ReturnsOrganizationsAuthority ( )
173
174
{
174
175
var context = new TestCommandContext ( ) ;
175
176
var uri = new Uri ( "https://example.com" ) ;
176
177
var msaTenantId = Guid . Empty ;
177
178
178
- const string expectedAuthority = CommonAuthority ;
179
+ // This is only the case because we're using MSA pass-through.. in the future, if and when we
180
+ // move away from MSA pass-through, this should be the common authority.
181
+ const string expectedAuthority = OrganizationsAuthority ;
179
182
180
183
var httpResponse = new HttpResponseMessage ( HttpStatusCode . Unauthorized )
181
184
{
Original file line number Diff line number Diff line change @@ -37,6 +37,12 @@ public async Task<string> GetAuthorityAsync(Uri organizationUri)
37
37
const string authorityBase = "https://login.microsoftonline.com/" ;
38
38
const string commonAuthority = authorityBase + "common" ;
39
39
40
+ // We should be using "/common" or "/consumer" as the authority for MSA but since
41
+ // Azure DevOps uses MSA pass-through (an internal hack to support MSA and AAD
42
+ // accounts in the same auth stack), which actually need to consult the "/organizations"
43
+ // authority instead.
44
+ const string msaAuthority = authorityBase + "organizations" ;
45
+
40
46
_context . Trace . WriteLine ( $ "HTTP: HEAD { organizationUri } ") ;
41
47
using ( HttpResponseMessage response = await HttpClient . HeadAsync ( organizationUri ) )
42
48
{
@@ -74,14 +80,14 @@ public async Task<string> GetAuthorityAsync(Uri organizationUri)
74
80
if ( tenantIds . Length == 1 && Guid . TryParse ( tenantIds [ 0 ] , out guid ) && guid == Guid . Empty )
75
81
{
76
82
_context . Trace . WriteLine ( $ "Found { AzureDevOpsConstants . VssResourceTenantHeader } header with MSA tenant ID (empty GUID).") ;
77
- return commonAuthority ;
83
+ return msaAuthority ;
78
84
}
79
85
}
80
86
}
81
87
}
82
88
83
89
// Use the common authority if we can't determine a specific one
84
- _context . Trace . WriteLine ( "Falling back to common authority. ") ;
90
+ _context . Trace . WriteLine ( $ "Unable to determine AAD/MSA tenant - falling back to common authority") ;
85
91
return commonAuthority ;
86
92
}
87
93
You can’t perform that action at this time.
0 commit comments