Skip to content

Commit

Permalink
Fix displaying secret in Vue component (#1244)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored May 6, 2020
1 parent 7183f24 commit 586fc5a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions resources/js/components/Clients.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<!-- Secret -->
<td style="vertical-align: middle;">
<code>{{ client.secret }}</code>
<code>{{ client.secret ? client.secret : '-' }}</code>
</td>

<!-- Edit Button -->
Expand Down Expand Up @@ -337,7 +337,7 @@
axios[method](uri, form)
.then(response => {
this.getClients();
this.clients.push(response.data);
form.name = '';
form.redirect = '';
Expand Down
21 changes: 17 additions & 4 deletions src/Http/Controllers/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Http\Response;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Http\Rules\RedirectRule;
use Laravel\Passport\Passport;

class ClientController
{
Expand Down Expand Up @@ -59,14 +60,20 @@ public function forUser(Request $request)
{
$userId = $request->user()->getAuthIdentifier();

return $this->clients->activeForUser($userId)->makeVisible('secret');
$clients = $this->clients->activeForUser($userId);

if (Passport::$hashesClientSecrets) {
return $clients;
}

return $clients->makeVisible('secret');
}

/**
* Store a new client.
*
* @param \Illuminate\Http\Request $request
* @return \Laravel\Passport\Client
* @return \Laravel\Passport\Client|array
*/
public function store(Request $request)
{
Expand All @@ -76,10 +83,16 @@ public function store(Request $request)
'confidential' => 'boolean',
])->validate();

return $this->clients->create(
$client = $this->clients->create(
$request->user()->getAuthIdentifier(), $request->name, $request->redirect,
false, false, (bool) $request->input('confidential', true)
)->makeVisible('secret');
);

if (Passport::$hashesClientSecrets) {
return ['secret' => $client->plainSecret] + $client->toArray();
}

return $client->makeVisible('secret');
}

/**
Expand Down

0 comments on commit 586fc5a

Please sign in to comment.