Skip to content

Commit dcb7e07

Browse files
author
Stéphan Kochen
authored
Merge pull request #5 from portier/featNormalize
Add `normalize` method
2 parents 18f1203 + d821a77 commit dcb7e07

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"require-dev": {
2424
"phpunit/phpunit": "^6.3",
25-
"phpstan/phpstan": "^0.8",
25+
"phpstan/phpstan": "^0.9",
2626
"squizlabs/php_codesniffer": "^3.1"
2727
}
2828
}

src/AbstractStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function generateNonce(string $email): string
4949

5050
/**
5151
* Fetch a URL using HTTP GET.
52-
* @param string $url The URL to fetch.
53-
* @return object An object with `ttl` and `data` properties.
52+
* @param string $url The URL to fetch.
53+
* @return \stdClass An object with `ttl` and `data` properties.
5454
*/
5555
public function fetch(string $url)
5656
{

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)