Skip to content

Commit

Permalink
fix: Fix conditional logic
Browse files Browse the repository at this point in the history
  • Loading branch information
siketyan committed Jun 1, 2023
1 parent fb31574 commit 0514060
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/Http/GoogleIapGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ public function __construct(
*/
public function callback(): ?Authenticatable
{
if (!\is_string($jwt = $this->request->header('x-goog-iap-jwt-assertion'))) {
// Required HTTP header is not provided.
return null;
}
/** @var null|Claims $claims */
$claims = null;

try {
$id = Assert::nonEmptyStringOrNull($this->request->header('x-goog-authenticated-user-id'));
$email = Assert::nonEmptyStringOrNull($this->request->header('x-goog-authenticated-user-email'));
$hd = ($email === null ? null : Assert::nonEmptyString(explode('@', $email)[1])) ?? 'example.com';
} catch (AssertionException $e) {
throw new MalformedClaimsException($e);
}
if (\is_string($jwt = $this->request->header('x-goog-iap-jwt-assertion'))) {
$claims = $this->googleIdTokenVerifier->verify($jwt);
} elseif ($this->options['allow_insecure_headers'] ?? false) {
try {
$id = Assert::nonEmptyStringOrNull($this->request->header('x-goog-authenticated-user-id'));
$email = Assert::nonEmptyStringOrNull($this->request->header('x-goog-authenticated-user-email'));
$hd = ($email === null ? null : Assert::nonEmptyString(explode('@', $email)[1])) ?? 'example.com';
} catch (AssertionException $e) {
throw new MalformedClaimsException($e);
}

if (($this->options['allow_insecure_headers'] ?? false) && ($id !== null || $email !== null)) {
$claims = new Claims([
'exp' => \PHP_INT_MAX,
'iat' => 1,
Expand All @@ -57,7 +57,9 @@ public function callback(): ?Authenticatable
'sub' => $id ?? 'accounts.google.com:0',
'email' => $email ?? 'accounts.google.com:[email protected]',
]);
} elseif (!($claims = $this->googleIdTokenVerifier->verify($jwt)) instanceof Claims) {
}

if (!$claims instanceof Claims) {
return null;
}

Expand Down

0 comments on commit 0514060

Please sign in to comment.