Skip to content

Commit

Permalink
feat: GoogleUser -> Claims
Browse files Browse the repository at this point in the history
  • Loading branch information
siketyan committed May 26, 2023
1 parent be427d1 commit 6f387f9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/GoogleUser.php → src/Claims.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use YumemiInc\GoogleIapLaravel\Internal\Assert;
use YumemiInc\GoogleIapLaravel\Internal\AssertionException;

class GoogleUser
class Claims
{
/**
* @var array{
Expand Down
2 changes: 1 addition & 1 deletion src/DefaultGoogleUserResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class DefaultGoogleUserResolver implements GoogleUserResolver
{
public function provide(GoogleUser $googleUser, UserProvider $userProvider): ?Authenticatable
public function provide(Claims $googleUser, UserProvider $userProvider): ?Authenticatable
{
return $userProvider->retrieveById($googleUser->sub());
}
Expand Down
6 changes: 3 additions & 3 deletions src/GoogleIdTokenVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public function __construct(
/**
* Verifies the JWT issued by Google IAP.
*
* @return null|GoogleUser claims in the JWT, or null if the token is invalid or malformed
* @return null|Claims claims in the JWT, or null if the token is invalid or malformed
*
* @throws MalformedClaimsException
*/
public function verify(string $jwt): ?GoogleUser
public function verify(string $jwt): ?Claims
{
if (!($claims = (new AccessToken())->verify($jwt, [
'certsLocation' => $this->jwksUrl,
Expand All @@ -35,7 +35,7 @@ public function verify(string $jwt): ?GoogleUser
return null;
}

$googleUser = new GoogleUser($claims);
$googleUser = new Claims($claims);

if ($this->issuer !== null && $googleUser->iss() !== $this->issuer) {
// Issuer verification failed.
Expand Down
2 changes: 1 addition & 1 deletion src/GoogleUserResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

interface GoogleUserResolver
{
public function provide(GoogleUser $googleUser, UserProvider $userProvider): ?Authenticatable;
public function provide(Claims $googleUser, UserProvider $userProvider): ?Authenticatable;
}
5 changes: 3 additions & 2 deletions src/Http/GoogleIapGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Http\Request;
use YumemiInc\GoogleIapLaravel\Claims;
use YumemiInc\GoogleIapLaravel\DefaultGoogleUserResolver;
use YumemiInc\GoogleIapLaravel\GoogleIdTokenVerifier;
use YumemiInc\GoogleIapLaravel\GoogleUserResolver;
Expand All @@ -34,12 +35,12 @@ public function callback(): ?Authenticatable
return null;
}

if (($googleUser = $this->googleIdTokenVerifier->verify($jwt)) === null) {
if (!($claims = $this->googleIdTokenVerifier->verify($jwt)) instanceof Claims) {
return null;
}

return $this->userProviderAdapter->provide(
$googleUser,
$claims,
$this->provider,
);
}
Expand Down

0 comments on commit 6f387f9

Please sign in to comment.