From bc97189a2608ff27507ba68d691ede7084c57b49 Mon Sep 17 00:00:00 2001 From: Michael Slowik Date: Thu, 17 Dec 2020 11:38:48 -0500 Subject: [PATCH] Add firebase authentication token to authenticable model --- src/FirebaseAuthenticable.php | 31 +++++++++++++++++++++++++++++++ src/FirebaseGuard.php | 5 +++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/FirebaseAuthenticable.php b/src/FirebaseAuthenticable.php index c8bdb3c..5461aed 100644 --- a/src/FirebaseAuthenticable.php +++ b/src/FirebaseAuthenticable.php @@ -11,6 +11,13 @@ trait FirebaseAuthenticable */ protected $claims; + /** + * Firebase token. + * + * @var string|null + */ + protected $firebaseAuthenticationToken; + /** * Get User by claim. * @@ -79,6 +86,30 @@ public function transformClaims(array $claims): array return $attributes; } + /** + * Set firebase token. + * + * @param string $token + * + * @return self + */ + public function setFirebaseAuthenticationToken($token) + { + $this->firebaseAuthenticationToken = $token; + + return $this; + } + + /** + * Get firebase token. + * + * @return string + */ + public function getFirebaseAuthenticationToken() + { + return $this->firebaseAuthenticationToken; + } + /** * Get the name of the unique identifier for the user. * diff --git a/src/FirebaseGuard.php b/src/FirebaseGuard.php index 91ab86a..8003fb7 100644 --- a/src/FirebaseGuard.php +++ b/src/FirebaseGuard.php @@ -40,10 +40,11 @@ public function user(Request $request) } try { - $token = $this->verifier->verifyIdToken($token); + $firebaseToken = $this->verifier->verifyIdToken($token); return app(config('auth.providers.users.model')) - ->resolveByClaims($token->getClaims()); + ->setFirebaseAuthenticationToken($token) + ->resolveByClaims($firebaseToken->getClaims()); } catch (\Exception $e) { if (config('app.debug')) { throw $e;