@@ -36,15 +36,22 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
36
36
[ NotNull ] AuthenticationProperties properties ,
37
37
[ NotNull ] OAuthTokenResponse tokens )
38
38
{
39
- var contextId = await ProcessIdTokenAndGetContactIdentifierAsync ( tokens , properties , identity ) ;
39
+ ( string tenantId , string webApiUrl ) = await ProcessIdTokenAndGetContactIdentifierAsync ( tokens , properties , identity ) ;
40
40
41
- if ( string . IsNullOrEmpty ( contextId ) )
41
+ if ( string . IsNullOrEmpty ( tenantId ) )
42
42
{
43
43
throw new InvalidOperationException ( "An error occurred trying to obtain the context identifier from the current user's identity claims." ) ;
44
44
}
45
45
46
- // Add contextId to the Options.UserInformationEndpoint (https://sod.superoffice.com/{0}/api/v1/user/currentPrincipal).
47
- var userInfoEndpoint = string . Format ( CultureInfo . InvariantCulture , Options . UserInformationEndpoint , contextId ) ;
46
+ if ( string . IsNullOrEmpty ( webApiUrl ) )
47
+ {
48
+ throw new InvalidOperationException ( "An error occurred trying to obtain the WebApi URL from the current user's identity claims." ) ;
49
+ }
50
+
51
+ // UserInfo endpoint must support multiple subdomains, i.e. sod, sod1, online, online1, online2, ...
52
+ // - subdomain only becomes known from id token
53
+ // Example WebApi Url https://sod.superoffice.com/Cust12345/api/
54
+ var userInfoEndpoint = string . Format ( CultureInfo . InvariantCulture , SuperOfficeAuthenticationConstants . FormatStrings . UserInfoEndpoint , webApiUrl ) ;
48
55
49
56
// Get the SuperOffice user principal.
50
57
using var request = new HttpRequestMessage ( HttpMethod . Get , userInfoEndpoint ) ;
@@ -69,7 +76,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
69
76
return new AuthenticationTicket ( context . Principal ! , context . Properties , Scheme . Name ) ;
70
77
}
71
78
72
- private async Task < string > ProcessIdTokenAndGetContactIdentifierAsync (
79
+ private async Task < ( string TenantId , string WebApiUrl ) > ProcessIdTokenAndGetContactIdentifierAsync (
73
80
[ NotNull ] OAuthTokenResponse tokens ,
74
81
[ NotNull ] AuthenticationProperties properties ,
75
82
[ NotNull ] ClaimsIdentity identity )
@@ -85,6 +92,7 @@ private async Task<string> ProcessIdTokenAndGetContactIdentifierAsync(
85
92
var tokenValidationResult = await ValidateAsync ( idToken , Options . TokenValidationParameters . Clone ( ) ) ;
86
93
87
94
var contextIdentifier = string . Empty ;
95
+ var webApiUrl = string . Empty ;
88
96
89
97
foreach ( var claim in tokenValidationResult . ClaimsIdentity . Claims )
90
98
{
@@ -93,6 +101,11 @@ private async Task<string> ProcessIdTokenAndGetContactIdentifierAsync(
93
101
contextIdentifier = claim . Value ;
94
102
}
95
103
104
+ if ( claim . Type == SuperOfficeAuthenticationConstants . ClaimNames . WebApiUrl )
105
+ {
106
+ webApiUrl = claim . Value ;
107
+ }
108
+
96
109
if ( claim . Type == SuperOfficeAuthenticationConstants . ClaimNames . SubjectIdentifier )
97
110
{
98
111
identity . AddClaim ( new Claim ( ClaimTypes . NameIdentifier , claim . Value ) ) ;
@@ -109,7 +122,7 @@ private async Task<string> ProcessIdTokenAndGetContactIdentifierAsync(
109
122
}
110
123
}
111
124
112
- return contextIdentifier ;
125
+ return ( contextIdentifier , webApiUrl ) ;
113
126
}
114
127
115
128
/// <summary>
0 commit comments