OAuth1 icon indicating copy to clipboard operation
OAuth1 copied to clipboard

Multisite - How share applications and credentials between blogs ?

Open Kilbourne opened this issue 8 years ago • 0 comments

I have a multisite install. The main blog is publicly available. User can register but have to insert a code, and depending on this code have access to particular subsite. The login is possible only from main site and when the user was logged in, he is automatically logged in in every subsite where is registered. Subsites are in a subfolder.

I want to recreate this structure on mobile App. Some questions:

  • On creating an application on root site, how sync it(create same application) on subsites?
  • On oAuth access step, how share and sync token credentials on subsite where the user is registered, so to not have to authorize every subsite?

Fundamentally i'd want to share the root site authorization to subsite.

I've tried this:

add_filter('rest_authentication_errors', function($result) {
    if (!is_user_logged_in_rootsite()) {
        return new WP_Error('restx_logged_out', 'Sorry, you must be logged in to make a request.', array('status' => 401));
    }
    if (!is_user_member_of_blog()) {
        return new WP_Error('restx_logged_out', 'Sorry, you must be registered to make a request.', array('status' => 401));
    }
    return $result;
});

function is_user_logged_in_rootsite() {
    switch_to_blog(1);
    $logged = is_user_logged_in() ? true : false;
    restore_current_blog();
    return $logged;
}

This works on main site but not on subsites.

Kilbourne avatar Apr 24 '16 16:04 Kilbourne