-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: refresh tokens * feat: refresh token model * refactor: refresh token feature * refactor: php version constraint * refactor: remove mongodb dependency, constraint is provided in another dependency
- Loading branch information
Jaspar Gupta
authored
May 27, 2020
1 parent
622037f
commit 248fac7
Showing
4 changed files
with
118 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace DesignMyNight\Mongodb\Passport\Bridge; | ||
|
||
use Jenssegers\Mongodb\Eloquent\Model; | ||
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; | ||
use League\OAuth2\Server\Entities\Traits\EntityTrait; | ||
use League\OAuth2\Server\Entities\Traits\RefreshTokenTrait; | ||
|
||
/** | ||
* Class RefreshToken | ||
* @package DesignMyNight\Mongodb\Passport\Bridge | ||
*/ | ||
class RefreshToken extends Model implements RefreshTokenEntityInterface | ||
{ | ||
use EntityTrait, RefreshTokenTrait; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected $casts = [ | ||
'revoked' => 'bool', | ||
]; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected $dates = ['expires_at']; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $guarded = []; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $incrementing = false; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $primaryKey = 'id'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $table = 'oauth_refresh_tokens'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $timestamps = false; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace DesignMyNight\Mongodb\Passport\Bridge; | ||
|
||
use Laravel\Passport\Bridge\RefreshTokenRepository as BaseRefreshTokenRepository; | ||
use Laravel\Passport\Events\RefreshTokenCreated; | ||
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; | ||
|
||
/** | ||
* Class RefreshTokenRepository | ||
* @package App\Passport\Bridge | ||
*/ | ||
class RefreshTokenRepository extends BaseRefreshTokenRepository | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getNewRefreshToken() | ||
{ | ||
return new RefreshToken(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isRefreshTokenRevoked($tokenId) | ||
{ | ||
$refreshToken = $this->database->table('oauth_refresh_tokens') | ||
->where('id', $tokenId)->first(); | ||
|
||
return $refreshToken === null || $refreshToken['revoked']; | ||
} | ||
|
||
/** | ||
* @param RefreshToken|RefreshTokenEntityInterface $refreshTokenEntity | ||
*/ | ||
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity) | ||
{ | ||
$refreshTokenEntity->newModelQuery()->create([ | ||
'id' => $id = $refreshTokenEntity->getIdentifier(), | ||
'access_token_id' => $accessTokenId = $refreshTokenEntity->getAccessToken()->getIdentifier(), | ||
'revoked' => false, | ||
'expires_at' => $refreshTokenEntity->getExpiryDateTime(), | ||
]); | ||
|
||
$this->events->dispatch(new RefreshTokenCreated($id, $accessTokenId)); | ||
} | ||
} |