Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Update Authentication validator #14

Closed
wants to merge 2 commits into from
Closed

Update Authentication validator #14

wants to merge 2 commits into from

Conversation

anton-kotik
Copy link
Contributor

Authentication validator is able to use adapter from the given AuthenticationService:

use My\Authentication\Adapter;
use My\Authentication\Storage;
use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Validator\Authentication as AuthenticationValidator;

$adapter = new Adapter();
$storage = new Storage();
$service = new AuthenticationService($storage, $adapter);

$validator = new AuthenticationValidator([
    'service' => $service,
]);

$validator->setIdentity('username');
$validator->isValid('password');


$adapter->setIdentity($identity);
$adapter->setCredential($credential);

$result = $this->service->authenticate($this->adapter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to change to $adapter instead of $this->adapter, as that's what we're authenticating against. I'll make that change during merge.

}
} else {
$adapter = $this->adapter;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract the logic for pulling the adapter from the AuthenticationService to a new method, so you can then instead say $adapter = $this->adapter ?: $this->getAdapterFromAuthenticationService();.

I'll make that change in a separate commit that I push to your branch.

break;
default:
$this->error(self::GENERAL);
if (!$result->isValid()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flip this conditional around:

if $result->isValid()) {
    return true;
}
// now do error work

Return early whenever you can, as it helps make the main code flow more readable.

I'll do this in a separate commit I push to your branch.

Result::FAILURE_CREDENTIAL_INVALID => self::CREDENTIAL_INVALID,
Result::FAILURE_IDENTITY_AMBIGUOUS => self::IDENTITY_AMBIGUOUS,
Result::FAILURE_UNCATEGORIZED => self::UNCATEGORIZED,
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue this should be a private constant (which we can do as we're now targeting PHP 5.6 and up in develop). I'll do this and push to your branch.

public function errorMessagesProvider()
{
return [
[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide names for each data set; these help us locate the specific set that caused an error more easily.

I'll do this in a separate commit that I push to your branch.

@weierophinney weierophinney mentioned this pull request Apr 12, 2018
weierophinney added a commit to weierophinney/zend-authentication that referenced this pull request Apr 12, 2018
weierophinney added a commit that referenced this pull request Apr 12, 2018
@weierophinney
Copy link
Member

Thanks, @27cm; merged with #37 for the 2.6.0 release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants