Skip to content

Commit c8a9609

Browse files
committed
Add domain hint using the whr query parameter for EntraID autehntications
https://learn.microsoft.com/en-us/answers/questions/855476/domain-hint-alternative-for-saml
1 parent f65e3e8 commit c8a9609

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/Surfnet/AzureMfa/Application/Service/AzureMfaService.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ public function createAuthnRequest(User $user, bool $forceAuthn = false): string
159159
// Create redirect response.
160160
$query = $authnRequest->buildRequestQuery();
161161

162+
// For Azure, add a "whr" query parameter with the domain of the user we want to authenticate.
163+
if (!$azureMfaIdentityProvider->isAzureAD()) {
164+
// EntraID does not accept a Subject like ADFS does, and there is no other way to pass the full user ID.
165+
// The Windows home realm hint (whr) parameter can help bypass the Microsoft Account Picker
166+
// (Home Realm Discovery) when the user has multiple accounts, thereby improving the user (SSO) experience.
167+
168+
// Get domain part of the user's email address (UPN) and use that as home realm
169+
$domain = $user->getEmailAddress()->getDomain();
170+
$query .= '&whr=' . urlencode($domain);
171+
}
172+
162173
return sprintf(
163174
'%s?%s',
164175
$destination->getUrl(),

0 commit comments

Comments
 (0)