Skip to content

Commit

Permalink
Add 'actingAsClient' static method to 'Passport' class
Browse files Browse the repository at this point in the history
  • Loading branch information
gdebrauwer committed Sep 9, 2019
1 parent a9a885d commit 66add57
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Carbon\Carbon;
use DateTimeInterface;
use Illuminate\Support\Facades\Route;
use League\OAuth2\Server\ResourceServer;

class Passport
{
Expand Down Expand Up @@ -405,6 +406,29 @@ public static function actingAs($user, $scopes = [], $guard = 'api')
return $user;
}

/**
* Set the current client for the application with the given scopes.
*
* @param  \Laravel\Passport\Client  $client
* @param  array  $scopes
* @return \Laravel\Passport\Client
*/
public static function actingAsClient($client, $scopes = [])
{
$mock = Mockery::mock(ResourceServer::class);

$mock->shouldReceive('validateAuthenticatedRequest')
->andReturnUsing(function ($request) use ($client, $scopes) {
return $request
->withAttribute('oauth_client_id', $client->id)
->withAttribute('oauth_scopes', $scopes);
});

app()->instance(ResourceServer::class, $mock);

return $client;
}

/**
* Set the storage location of the encryption keys.
*
Expand Down

0 comments on commit 66add57

Please sign in to comment.