Created
December 26, 2020 17:14
-
-
Save onurkose/02235f0ed0629a642b3e6ec79307bf74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Firebase; | |
use App\Models\User\User; | |
use Exception; | |
use Firebase\Auth\Token\Verifier; | |
class Guard | |
{ | |
protected $verifier; | |
/** | |
* Guard constructor. | |
* @param Verifier $verifier | |
*/ | |
public function __construct(Verifier $verifier) | |
{ | |
$this->verifier = $verifier; | |
} | |
/** | |
* @param $request | |
* @return User|null | |
* @throws Exception | |
*/ | |
public function user($request): ?User | |
{ | |
$token = $request->bearerToken(); | |
try { | |
$firebaseToken = $this->verifier->verifyIdToken($token); | |
return app(config('auth.providers.users.model')) | |
->setFirebaseAuthenticationToken($token) | |
->resolveByClaims($firebaseToken->claims()); | |
} catch (Exception $e) { | |
if (config('app.debug')) { | |
throw $e; | |
} | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment