forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request laravel#42 from eurides-eu/feature/oauth-setup
Add console command to create oauth clients for organizations
- Loading branch information
Showing
7 changed files
with
168 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\oAuthClients; | ||
|
||
use App\OAuthClients\Commands\CreateOAuthClient as CreateOAuthClientCommand; | ||
use Illuminate\Console\Command; | ||
use Madewithlove\Tactician\Traits\DispatchesJobs; | ||
|
||
class CreateOAuthClient extends Command | ||
{ | ||
use DispatchesJobs; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'eurides:oauth-client:create {organizationId}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create an oAuth Client for an organization'; | ||
|
||
/** | ||
* Create a new command instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$organizationId = $this->argument('organizationId'); | ||
|
||
$client = $this->dispatch(new CreateOAuthClientCommand($organizationId)); | ||
|
||
$this->info("OAuth Client created successfully\n ID: $client->id\n Secret: $client->secret"); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace App\OAuthClients\CommandHandlers; | ||
|
||
use App\Models\Organization; | ||
use App\OAuthClients\Commands\CreateOAuthClient as Command; | ||
use Laravel\Passport\ClientRepository; | ||
|
||
class CreateOAuthClient | ||
{ | ||
protected $clientRepository; | ||
|
||
/** | ||
* CreateOAuthClient constructor. | ||
* | ||
* @param $clientFactory | ||
*/ | ||
public function __construct(ClientRepository $clientFactory) | ||
{ | ||
$this->clientRepository = $clientFactory; | ||
} | ||
|
||
/** | ||
* @param Command $command | ||
* | ||
* @return \Laravel\Passport\Client | ||
*/ | ||
public function handle(Command $command) | ||
{ | ||
$organization = Organization::findOrFail($command->getOrganizationId()); | ||
|
||
$clientName = "$organization->name Client Credentials Grant Client"; | ||
|
||
$client = $this->clientRepository->create(null, $clientName, url('/')); | ||
|
||
$client->organization_id = $command->getOrganizationId(); | ||
|
||
$client->save(); | ||
|
||
return $client; | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace App\OAuthClients\Commands; | ||
|
||
class CreateOAuthClient | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $organizationId; | ||
|
||
/** | ||
* CreateOAuthClient constructor. | ||
* | ||
* @param string $organizationId | ||
*/ | ||
public function __construct(string $organizationId) | ||
{ | ||
$this->organizationId = $organizationId; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getOrganizationId(): string | ||
{ | ||
return $this->organizationId; | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
use League\Tactician\Handler\CommandHandlerMiddleware; | ||
use League\Tactician\Plugins\LockingMiddleware; | ||
use Madewithlove\Tactician\Middlewares\TransactionMiddleware; | ||
|
||
return [ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Middlewares | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The middlewares to inject into your command bus, you can simply pass the class name | ||
| and the middleware will be resolved from the IoC Container. | ||
| | ||
*/ | ||
|
||
'middlewares' => [ | ||
LockingMiddleware::class, | ||
TransactionMiddleware::class, | ||
CommandHandlerMiddleware::class, | ||
], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Replacements | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The ContainerLocator provided by this package will match your commands | ||
| to your handlers by replacing part of the command namespace. | ||
| | ||
| Use this config to customize what to look in the Command namespace and | ||
| what to replace it with. | ||
| | ||
*/ | ||
|
||
'replacements' => [ | ||
'origin' => 'Commands', | ||
'target' => 'CommandHandlers', | ||
], | ||
]; |