Skip to content
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

Remove direct access to models #96

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
.idea/
/vendor
/.idea
/composer.lock
6 changes: 2 additions & 4 deletions src/Http/Controllers/AccessTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public function issueToken(ServerRequestInterface $request)
$tokenId = $this->jwt->parse($payload['access_token'])->getClaim('jti');
$token = $this->tokens->find($tokenId);

if ($token->client->firstParty() && LumenPassport::$allowMultipleTokens) {
// We keep previous tokens for password clients
} else {
if (!$token->client->firstParty() || !LumenPassport::$allowMultipleTokens) {
$this->revokeOrDeleteAccessTokens($token, $tokenId);
}
}
Expand Down Expand Up @@ -80,7 +78,7 @@ private function makePasswordGrant()
*/
protected function revokeOrDeleteAccessTokens(Token $token, $tokenId)
{
$query = Token::where('user_id', $token->user_id)->where('client_id', $token->client_id);
$query = Passport::token()->where('user_id', $token->user_id)->where('client_id', $token->client_id);

if ($tokenId) {
$query->where('id', '<>', $tokenId);
Expand Down
16 changes: 11 additions & 5 deletions src/PassportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Dusterio\LumenPassport;

use Dusterio\LumenPassport\Console\Commands\Purge;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Connection;

Expand All @@ -13,13 +14,15 @@
class PassportServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
public function register()
{
$this->app->singleton(Connection::class, function() {
$this->app->singleton(Connection::class, function () {
$conn = env('PASSPORT_CONNECTION');
if ($conn != null) {
return DB::connection($conn);
}
return $this->app['db.connection'];
});

Expand All @@ -35,10 +38,13 @@ public function boot()
]);
}
}

/**
* Bootstrap any application services.
*
* @return void
*/
public function register()
public function boot()
{
}
}