Skip to content

Commit

Permalink
Merge pull request #8 from firevel/feature/store-raw-token
Browse files Browse the repository at this point in the history
Add firebase authentication token to authenticable model
  • Loading branch information
sl0wik authored Dec 17, 2020
2 parents fe1cde0 + bc97189 commit 35bcd09
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
31 changes: 31 additions & 0 deletions src/FirebaseAuthenticable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ trait FirebaseAuthenticable
*/
protected $claims;

/**
* Firebase token.
*
* @var string|null
*/
protected $firebaseAuthenticationToken;

/**
* Get User by claim.
*
Expand Down Expand Up @@ -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.
*
Expand Down
5 changes: 3 additions & 2 deletions src/FirebaseGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 35bcd09

Please sign in to comment.