Skip to content

Commit ff6366b

Browse files
committed
Fix ClientController::store() breaking change introduced via #1745
```php - if (Passport::$hashesClientSecrets) { - return ['plainSecret' => $client->plainSecret] + $client->toArray(); - } + $client->secret = $client->plainSecret; return $client->makeVisible('secret'); ``` This change obviously breaks usages that previously relied on the return type array with the additional 'plainSecret' data. E.g., the old Vue components used the plainSecret to present that to the user so that he could save it, etc. Since hashing is now mandatory, I restored the previous behavior without the now obsolete `Passport::$hashesClientSecrets` check: ```php return ['plainSecret' => $client->plainSecret] + $client->toArray(); ``` I also updated the tests. I know it looks a bit fishy but I had not much choice since it's a unit test … (didn't want to make too big of a change out of this … it's deprecated anyways …)
1 parent 36af05a commit ff6366b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/Http/Controllers/ClientController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function forUser(Request $request): Collection
3838
/**
3939
* Store a new client.
4040
*/
41-
public function store(Request $request): Client
41+
public function store(Request $request): array
4242
{
4343
$this->validation->make($request->all(), [
4444
'name' => ['required', 'string', 'max:255'],
@@ -53,9 +53,7 @@ public function store(Request $request): Client
5353
$request->user(),
5454
);
5555

56-
$client->secret = $client->plainSecret;
57-
58-
return $client->makeVisible('secret');
56+
return ['plainSecret' => $client->plainSecret] + $client->toArray();
5957
}
6058

6159
/**

tests/Unit/ClientControllerTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function test_clients_can_be_stored()
5151
$clients->shouldReceive('createAuthorizationCodeGrantClient')
5252
->once()
5353
->with('client name', ['http://localhost'], true, $user)
54-
->andReturn($client = new Client);
54+
->andReturn($client = new Client(['name' => 'client']));
5555

5656
$redirectRule = m::mock(RedirectRule::class);
5757

@@ -70,7 +70,10 @@ public function test_clients_can_be_stored()
7070
$clients, $validator, $redirectRule
7171
);
7272

73-
$this->assertEquals($client, $controller->store($request));
73+
$this->assertEquals([
74+
'name' => $client->name,
75+
'plainSecret' => $client->plainSecret,
76+
], $controller->store($request));
7477
}
7578

7679
public function test_public_clients_can_be_stored()
@@ -89,7 +92,7 @@ public function test_public_clients_can_be_stored()
8992
$clients->shouldReceive('createAuthorizationCodeGrantClient')
9093
->once()
9194
->with('client name', ['http://localhost'], false, $user)
92-
->andReturn($client = new Client);
95+
->andReturn($client = new Client(['name' => 'client']));
9396

9497
$redirectRule = m::mock(RedirectRule::class);
9598

@@ -109,7 +112,10 @@ public function test_public_clients_can_be_stored()
109112
$clients, $validator, $redirectRule
110113
);
111114

112-
$this->assertEquals($client, $controller->store($request));
115+
$this->assertEquals([
116+
'name' => $client->name,
117+
'plainSecret' => $client->plainSecret,
118+
], $controller->store($request));
113119
}
114120

115121
public function test_clients_can_be_updated()

0 commit comments

Comments
 (0)