Skip to content

Add RefreshToken model to the list aliases #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/MongodbPassportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DesignMyNight\Mongodb\Passport\AuthCode;
use DesignMyNight\Mongodb\Passport\Client;
use DesignMyNight\Mongodb\Passport\PersonalAccessClient;
use DesignMyNight\Mongodb\Passport\RefreshToken;
use DesignMyNight\Mongodb\Passport\Token;

class MongodbPassportServiceProvider extends ServiceProvider
Expand All @@ -21,11 +22,13 @@ public function register()
$loader->alias('Laravel\Passport\Client', Client::class);
$loader->alias('Laravel\Passport\PersonalAccessClient', PersonalAccessClient::class);
$loader->alias('Laravel\Passport\Token', Token::class);
$loader->alias('Laravel\Passport\RefreshToken', RefreshToken::class);
} else {
class_alias('Laravel\Passport\AuthCode', AuthCode::class);
class_alias('Laravel\Passport\Client', Client::class);
class_alias('Laravel\Passport\PersonalAccessClient', PersonalAccessClient::class);
class_alias('Laravel\Passport\Token', Token::class);
class_alias('Laravel\Passport\RefreshToken', RefreshToken::class);
}
}
}
84 changes: 84 additions & 0 deletions src/Passport/RefreshToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace DesignMyNight\Mongodb\Passport;

use Jenssegers\Mongodb\Eloquent\Model;

class RefreshToken extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'oauth_refresh_tokens';

/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;

/**
* The guarded attributes on the model.
*
* @var array
*/
protected $guarded = [];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'revoked' => 'bool',
];

/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = [
'expires_at',
];

/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;

/**
* Get the access token that the refresh token belongs to.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function accessToken()
{
return $this->belongsTo(Passport::tokenModel());
}

/**
* Revoke the token instance.
*
* @return bool
*/
public function revoke()
{
return $this->forceFill(['revoked' => true])->save();
}

/**
* Determine if the token is a transient JWT token.
*
* @return bool
*/
public function transient()
{
return false;
}
}