Skip to content

Commit 13f5625

Browse files
authored
Merge pull request #16 from portier/feat/state
Fix implementation of `state`
2 parents fe58bc3 + 9515146 commit 13f5625

File tree

4 files changed

+9
-26
lines changed

4 files changed

+9
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ $app->post('/auth', function($req, $res) use ($portier) {
5050
});
5151

5252
$app->post('/verify', function($req, $res) use ($portier) {
53-
$result = $portier->verify($req->getParsedBody()['id_token']);
53+
$email = $portier->verify($req->getParsedBody()['id_token']);
5454

5555
$res = $res
5656
->withStatus(200)
5757
->withHeader('Content-Type', 'text/html; charset=utf-8');
5858

5959
$res->getBody()->write(
6060
<<<EOF
61-
<p>Verified email address {$result->email}!</p>
61+
<p>Verified email address ${email}!</p>
6262
EOF
6363
);
6464

client-tester.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
break;
3434
case 'verify':
3535
try {
36-
$result = $client->verify($cmd[1]);
37-
echo "ok\t{$result->email}\t{$result->state}\n";
36+
$email = $client->verify($cmd[1]);
37+
echo "ok\t{$email}\n";
3838
} catch (Throwable $err) {
3939
$msg = implode(' ', explode("\n", $err->getMessage()));
4040
echo "err\t{$msg}\n";

src/Client.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static function normalize(string $email): string
9797
* Start authentication of an email address.
9898
*
9999
* @param string $email email address to authenticate
100-
* @param string $state state to carry along, will be returned in `verify`
100+
* @param string $state arbitrary state that is returned to the redirect URL via the `state` query parmmeter
101101
*
102102
* @return string URL to redirect the browser to
103103
*/
@@ -129,8 +129,10 @@ public function authenticate(string $email, string $state = null): string
129129
* Verify a token received on our `redirect_uri`.
130130
*
131131
* @param string $token the received `id_token` parameter value
132+
*
133+
* @return string the verified email address
132134
*/
133-
public function verify(string $token): VerifyResult
135+
public function verify(string $token): string
134136
{
135137
assert(!empty($token));
136138
assert(!empty($this->broker));
@@ -213,7 +215,7 @@ public function verify(string $token): VerifyResult
213215
}
214216

215217
// Return the normalized email.
216-
return new VerifyResult($email, $state);
218+
return $email;
217219
}
218220

219221
/**

src/VerifyResult.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)