From 8eccc65edd483d94388f49ce7af66668e85c7148 Mon Sep 17 00:00:00 2001 From: Aiosa Date: Fri, 25 Aug 2023 20:31:07 +0200 Subject: [PATCH] User info invalid in WP multisite, user incomplete, missing name etc. Buggy behaviour - add automatically to the blog. --- inc/jwt/includes/class-jwt-public.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/inc/jwt/includes/class-jwt-public.php b/inc/jwt/includes/class-jwt-public.php index b9a11e2c9..d4179a92a 100644 --- a/inc/jwt/includes/class-jwt-public.php +++ b/inc/jwt/includes/class-jwt-public.php @@ -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 );