-
Notifications
You must be signed in to change notification settings - Fork 99
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
SessionAuthenticator 'identify' attribute does not work #683
Comments
SessionAuthenticator + identify should usually only have Your session authenticator configuration should look like: $authenticationService->loadAuthenticator('Authentication.Session', [
'identify' => true,
'fields' => [
AbstractIdentifier::CREDENTIAL_USERNAME => 'id',
],
]); |
Okay, thank you. I will check that. |
So I get another exception in these lines: public function identify(array $credentials): ArrayAccess|array|null
{
if (!isset($credentials[self::CREDENTIAL_USERNAME])) {
return null;
}
$identity = $this->_findIdentity($credentials[self::CREDENTIAL_USERNAME]);
if (array_key_exists(self::CREDENTIAL_PASSWORD, $credentials)) {
$password = $credentials[self::CREDENTIAL_PASSWORD];
if (!$this->_checkPassword($identity, $password)) {
return null;
}
}
return $identity;
} Authentication\Identifier\PasswordIdentifier::_findIdentity(): Argument #1 ($identifier) must be of type string, int given, called in /workspace/vendor/cakephp/authentication/src/Identifier/PasswordIdentifier.php on line 100 Here is the documentation: identify: Set this key with a value of bool true to enable checking the session credentials against the identifiers. When true, the configured Identifiers are used to identify the user using data stored in the session on each request. Default value is false. fields: Allows you to map the username field to the unique identifier in your user storage. Defaults to username. This option is used when the identify option is set to true. So maybe it has to be this configuration: $authenticationService->loadAuthenticator('Authentication.Session', [
'identify' => true,
'fields' => [
AbstractIdentifier::CREDENTIAL_USERNAME => 'email',
],
]); |
With that configuration, the login is possible, and it checks the session's email against the user's email from the database. But what about the password? I need a mechanism to close all open sessions when the password is changed by the user. Maybe I need to implement that myself? |
Yes, you're right. I forgot about the additional type constraints. Using the field you use for unique usernames sounds right.
Yes. If you have a solution that could work generally please consider opening a pull request or issue as I think this would be a useful addition to the authentication plugin. |
I would like to check the logged-in user with every request to see if their email address or password has changed. If a user changes their password, every existing session should also be terminated.
This should apparently be possible to solve with identify => true in the SessionAuthenticator. However, if I enable this, the session is always terminated because, in the following lines, the hashed password from the session is hashed again and compared with the hashed password from the database, which results in a FAILURE_CREDENTIALS_INVALID result. Please also see attached file.
SessionAuthenticator.php :
The login remains unsuccessful if I try to log in without cookies.
Here is my configuration:
The text was updated successfully, but these errors were encountered: