Skip to content

Commit

Permalink
fix: googleUser -> claims
Browse files Browse the repository at this point in the history
  • Loading branch information
siketyan committed May 26, 2023
1 parent 58f46ec commit 039df86
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ Authentication guard on Laravel for verifying requests from Google IAP (Identity

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider;
use YumemiInc\GoogleIapLaravel\Claims;
use YumemiInc\GoogleIapLaravel\GoogleUserResolver;

class AppGoogleUserResolver implements GoogleUserResolver
{
public function provide(GoogleUser $googleUser, UserProvider $userProvider): ?Authenticatable
public function provide(Claims $claims, UserProvider $userProvider): ?Authenticatable
{
return $userProvider->retrieveByCredentials([
'google_user_id' => $googleUser->sub(),
'google_user_id' => $claims->sub(),
]);
}
}
Expand All @@ -51,11 +53,14 @@ Authentication guard on Laravel for verifying requests from Google IAP (Identity
}
```

4. Set the Google IAP guard as the default.
4. Use the guard provided in this package.
```php
<?php // config/auth.php

'defaults' => [
'guard' => 'google',
'guards' => [
'google-iap' => [
'driver' => 'google-iap',
'provider' => 'users',
],
]
```
4 changes: 2 additions & 2 deletions src/DefaultGoogleUserResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

class DefaultGoogleUserResolver implements GoogleUserResolver
{
public function provide(Claims $googleUser, UserProvider $userProvider): ?Authenticatable
public function provide(Claims $claims, UserProvider $userProvider): ?Authenticatable
{
return $userProvider->retrieveById($googleUser->sub());
return $userProvider->retrieveById($claims->sub());
}
}
8 changes: 4 additions & 4 deletions src/GoogleIdTokenVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ public function verify(string $jwt): ?Claims
return null;
}

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

if ($this->issuer !== null && $googleUser->iss() !== $this->issuer) {
if ($this->issuer !== null && $claims->iss() !== $this->issuer) {
// Issuer verification failed.
return null;
}

if ($this->audience !== null && $googleUser->aud() !== $this->audience) {
if ($this->audience !== null && $claims->aud() !== $this->audience) {
// Audience verification failed.
return null;
}

return $googleUser;
return $claims;
}
}
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(Claims $googleUser, UserProvider $userProvider): ?Authenticatable;
public function provide(Claims $claims, UserProvider $userProvider): ?Authenticatable;
}

0 comments on commit 039df86

Please sign in to comment.