My WP multisite has more than 300 sites which means I need to store all 300 redirect_urls in Azure AD B2C, but this number of redirect_urls cannot be stored in AD B2C as the maximum number of redirect URIs is 256.
What I do is that when the user logs in through www.abc1.com/wp-admin
, it first redirects to B2C login page with the default redirect URL (www.abc.com
) that I set. Once the token is verified, the user is redirected to their site (www.abc1.com
).
But it doesn't seem to work. I am even not sure if it is the best approach to redirect the user to site they want to access by this way.
//fetch the user' site id and redirect to the site.
$user_blogs = get_blogs_of_user($userID);
if (!empty($user_blogs)) {
$siteInfo = array();
foreach ($user_blogs as $site_id => $site_values) {
$siteInfo[] = $site_values->siteurl;
}
$redirect_url = $siteInfo[0] ; // to the primary site..
}
// Set cookies to authenticate on WP side
wp_set_auth_cookie($userID);
//Redirect to primary site that assigned to the user
wp_safe_redirect($redirect_url);