oidc-wp / openid-connect-generic

WordPress plugin to provide an OpenID Connect Generic client
https://wordpress.org/plugins/daggerhart-openid-connect-generic/
258 stars 155 forks source link

After creating a new user it does not log in automatically #274

Open Matteo182 opened 3 years ago

Matteo182 commented 3 years ago

I log in with a user not present on WordPress, but present on the main platform. The plugin correctly creates the new user on WordPress, but after creating the user it does not log in automatically, it takes me back to the home page without having logged in.

this problem occurred after upgrading to the Versione 3.8.1 WordPress Version : 5.6.1

in the logs it writes : string(63) "Successful login for: 59cf34bd-6822-40e5-80d3-11892dce12df (97)"

so i guess this statement doesn't work: do_action( 'wp_login', $user->user_login, $user ); in \daggerhart-openid-connect-generic\includes\openid-connect-generic-client-wrapper.php line 512

how can i fix this error?

thank you so much

timnolte commented 3 years ago

Can you provide all of the following details:

WordPress Environment

Also, I'm curious how you opened this issue without having to choose an Issue Template? You should have been promoted with choosing your type of issue and then asked some questions.

Matteo182 commented 3 years ago

Hi @timnolte , thanks for answering me,

WordPress Environment

Website URL: now it is under vpn PHP Version: 7.3.5 WordPress Version: 5.6.1 Plugin Version: 3.8.1 Identity Provider: AWS Relevant Plugin Settings:

I don't understand what you mean, I clicked on support and wrote a generic support question, where should I go? :)

thanks

timnolte commented 3 years ago

OK, I think I would have expected you to open a Bug Report instead if a general question.

Matteo182 commented 3 years ago

ok I found the error, I need to normalize the username before creating the user.

add_filter( 'openid-connect-generic-alter-user-data', [$this, 'pre_username_normalize'], 10, 2);

private static function pre_username_normalize($user_data, $user_claim){ //normalizzo lo username $user_data['user_login'] = strtolower( preg_replace( '/[^a-zA-Z_0-9]/', '', iconv( 'UTF-8', 'ASCII//TRANSLIT',
$user_data['user_login'] ) ) );

    return $user_data;
}

i inserted this filter function but it doesn't work, can you tell me how do i modify user_login in the array before creating the user?

this solves the error, probably in the previous version of your plugin there was a normalization of the user_login?

thank you so much

timnolte commented 3 years ago

@Matteo182 so I believe we have 1 or 2 open issues in regards to how identities are matched. As you indicated I believe we are in fact missing some normalization.

Matteo182 commented 3 years ago

Hi @timnolte . I was able to solve this problem using this hook. I just removed static from the wording and the function is executed correctly in the hook.

add_filter( 'openid-connect-generic-alter-user-data', [$this, 'pre_username_normalize'], 10, 2);

private function pre_username_normalize($user_data, $user_claim){ //normalizzo lo username $user_data['user_login'] = strtolower( preg_replace( '/[^a-zA-Z_0-9]/', '', iconv( 'UTF-8', 'ASCII//TRANSLIT', $user_data['user_login'] ) ) );

return $user_data;

}