Skip to content

Bugs on WP multisite with token retrieval, if user not part of the blog #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions inc/jwt/includes/class-jwt-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ public function generate_token( WP_REST_Request $request ) {
);
}

$blog_id = get_current_blog_id();
if (!is_user_member_of_blog($user->data->ID, $blog_id)) {
$added = add_user_to_blog($blog_id, $user->data->ID, 'subscriber');
if (is_wp_error($added)) {
$error_code = $added->get_error_code();
return new WP_Error(
'[lp_jwt_auth] ' . $error_code,
$added->get_error_message( $error_code ),
array(
'status' => 403,
)
);
}
//need to refresh data, username ignored anyway...
$user = new WP_User( $user->data->ID, $username, $blog_id);
}

/** Valid credentials, the user exists create the according Token */
$issued_at = time();
$not_before = apply_filters( 'lp_jwt_auth_not_before', $issued_at, $issued_at );
Expand Down