Hello again. sorry for spamming this repo but still need some help. I managed to install the plugin. But it seems the plugin doesnt import my wp users.
I used this rest point
/* Create Custom Endpoint */
add_action('rest_api_init', 'create_keycloak_endpoints');
function create_keycloak_endpoints() {
register_rest_route(
'wp/v2',
'/keycloak-user-migration/(?P<username>.+)',
[
'methods' => 'GET',
'callback' => 'keycloak_get',
]
);
register_rest_route(
'wp/v2',
'/keycloak-user-migration/(?P<username>.+)',
[
'methods' => 'POST',
'callback' => 'keycloak_post',
]
);
}
function keycloak_get($request) {
$username = $request['username'];
$user = get_user_by('email', $username);
if (!$user) {
$user = get_user_by('login', $username);
}
if (!$user) {
write_log('not found '.$username);
return new WP_REST_Response(['message' => 'not found '.$username], 404);
}
return [
'id' => $user->ID,
'username' => $user->user_login,
'email' => $user->user_email,
'firstName' => $user->user_firstname,
'lastName' => $user->user_lastname,
'enabled' => true,
'emailVerified' => true,
];
}
function keycloak_post($request) {
$username = $request['username'];
$password = $request['password'];
$user = get_user_by('login', $username);
if (!$user) {
$user = get_user_by('email', $username);
}
if (!$user || !wp_check_password($password, $user->user_pass, $user->ID)) {
write_log('wrong_password for '.$username);
return new WP_REST_Response(['message' => 'wrong_password for '.$username], 404);
}
return true;
}
if (!function_exists('write_log')) {
function write_log($log) {
if (is_array($log) || is_object($log)) {
error_log(print_r($log, true));
} else {
error_log($log);
}
}
}
But using the url in the plugin: https://mydomain.com/wp-json/wp/v2/keycloak-user-migration
with and without /doesnt work.
I dont get any logs on keycloak, nor on wp if there is errors during calls.
When I try to syncronize, it says skipped syncronziation as synchronisation is beeing processed
Have you tried adding some debug logs to the endpoints to see if they're being called at all?
Have you verified that manually calling the POST endpoint works correctly? I'm not sure how to read your code (I haven't done PHP in a while), but at first glance it seems the POST endpoint is not reading the password from the JSON body.
A lack of logs on Keycloak's side may indicate that the user is just not passing password verification (perhaps because of the POST endpoint not being configured correctly).
Hello again. sorry for spamming this repo but still need some help. I managed to install the plugin. But it seems the plugin doesnt import my wp users.
I used this rest point
and I can also call it with `curl -X GET "https://mydomain.com/wp-json/wp/v2/keycloak-user-migration/testuser" which gives me a correct response.
But using the url in the plugin:
https://mydomain.com/wp-json/wp/v2/keycloak-user-migration
with and without/
doesnt work.I dont get any logs on keycloak, nor on wp if there is errors during calls. When I try to syncronize, it says skipped syncronziation as synchronisation is beeing processed
What am I doing wrong again? Any hints?