admin管理员组文章数量:1326049
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/wp-admin
, it first redirects to B2C login page with the default redirect URL (www.abc
) that I set. Once the token is verified, the user is redirected to their site (www.abc1
).
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);
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/wp-admin
, it first redirects to B2C login page with the default redirect URL (www.abc
) that I set. Once the token is verified, the user is redirected to their site (www.abc1
).
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);
Share
Improve this question
edited Aug 11, 2020 at 5:37
Nate Allen
2,1062 gold badges16 silver badges23 bronze badges
asked Aug 10, 2020 at 1:56
princeexpeditionprinceexpedition
237 bronze badges
2
- When you say "But it doesn't seem to work," what specifically isn't working about it? They're not getting logged in? They are getting redirected to the wrong site? It's throwing an error? More details will help. – Nate Allen Commented Aug 11, 2020 at 5:52
- It redirects back to the user site but without active session. Anyway, I placed this above code inside add_action('wp_loaded', 'b2c_verify_token'); but I guess I need to set the cookies like this add_action('init', 'set_auth_cookie'); before the wp_loaded action triggers. – princeexpedition Commented Aug 11, 2020 at 14:58
1 Answer
Reset to default 1I can see a few issues with this approach:
- If the user doesn't belong to a site yet, they won't get redirected correctly because
$redirect_url
won't be defined. - If the user belongs to more than 1 site, they will always be redirected to the site with the lowest ID, not necessarily the one they're trying to log into.
Have you tried any Azure SSO plugins? I built an intranet for a client that uses Azure for employees to log into the site, and we had great results using Single Sign-on with Azure Active Directory (for WordPress). It's supposed to work with multisite; you'll just need to make sure it's configured correctly on each site.
本文标签: plugin developmentWordPress Multisite with Azure B2C redirecturls after Login
版权声明:本文标题:plugin development - WordPress Multisite with Azure B2C redirect_urls after Login 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742196819a2431230.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论