Skip to content

Commit d821a77

Browse files
author
Stéphan Kochen
committed
Add a normalize helper
1 parent 90716ae commit d821a77

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Client.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ public function __construct(StoreInterface $store, string $redirectUri)
4242
$this->clientId = self::getOrigin($this->redirectUri);
4343
}
4444

45+
/**
46+
* Normalize one or more email addresses.
47+
*
48+
* This method is useful when comparing user input to an email address
49+
* returned in a Portier token. It is not necessary to call this before
50+
* `authenticate`, normalization is already part of the authentication
51+
* process.
52+
*
53+
* This is currently implemented by making an HTTP call to Portier, without
54+
* cache.
55+
*
56+
* @param string[] $emails Email addresses to normalize.
57+
* @return string[] Normalized email addresses, empty strings for invalid.
58+
*/
59+
public function normalize(array $emails): array
60+
{
61+
$res = $this->store->guzzle->post(
62+
$this->broker . '/normalize',
63+
['body' => implode("\n", $emails)]
64+
);
65+
return explode("\n", (string) $res->getBody());
66+
}
67+
4568
/**
4669
* Start authentication of an email address.
4770
* @param string $email Email address to authenticate.

0 commit comments

Comments
 (0)