Skip to content

Commit 21f89cc

Browse files
committed
Merge branch '11.x'
# Conflicts: # CHANGELOG.md # src/Client.php
2 parents c97dbf0 + 2642f36 commit 21f89cc

File tree

7 files changed

+127
-41
lines changed

7 files changed

+127
-41
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Release Notes
22

3-
## [Unreleased](https://github.com/laravel/passport/compare/v11.10.4...master)
3+
## [Unreleased](https://github.com/laravel/passport/compare/v11.10.5...master)
4+
5+
## [v11.10.5](https://github.com/laravel/passport/compare/v11.10.4...v11.10.5) - 2024-02-09
6+
7+
* [11.x] Fix getting/setting client scopes and grant types by [@axlon](https://github.com/axlon) in https://github.com/laravel/passport/pull/1717
48

59
## [v11.10.4](https://github.com/laravel/passport/compare/v11.10.2...v11.10.4) - 2024-01-30
610

phpunit.xml.dist

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
beStrictAboutTestsThatDoNotTestAnything="false"
5-
bootstrap="vendor/autoload.php"
6-
colors="true"
7-
convertDeprecationsToExceptions="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
processIsolation="false"
12-
stopOnFailure="false"
13-
>
2+
<phpunit colors="true">
143
<testsuites>
154
<testsuite name="Unit">
165
<directory suffix="Test.php">./tests/Unit</directory>

src/Bridge/ClientRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function validateClient($clientIdentifier, $clientSecret, $grantType)
7272
*/
7373
protected function handlesGrant($record, $grantType)
7474
{
75-
if (is_array($record->grant_types) && ! in_array($grantType, $record->grant_types)) {
75+
if (! $record->hasGrantType($grantType)) {
7676
return false;
7777
}
7878

src/Client.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -108,34 +108,15 @@ public function tokens()
108108
}
109109

110110
/**
111-
* Get the grant types the client can use.
111+
* The temporary non-hashed client secret.
112112
*
113-
* @return array|null
114-
*/
115-
public function getGrantTypesAttribute()
116-
{
117-
return $this->attributes['grant_types'] ?? null;
118-
}
119-
120-
/**
121-
* Get the scopes for the client.
122-
*
123-
* @return array|null
124-
*/
125-
public function getScopesAttribute()
126-
{
127-
return $this->attributes['scopes'] ?? null;
128-
}
129-
130-
/**
131-
* Set the scopes for the client.
113+
* This is only available once during the request that created the client.
132114
*
133-
* @param array|null $scopes
134-
* @return void
115+
* @return string|null
135116
*/
136-
public function setScopesAttribute(?array $scopes)
117+
public function getPlainSecretAttribute()
137118
{
138-
$this->attributes['scopes'] = $scopes;
119+
return $this->plainSecret;
139120
}
140121

141122
/**
@@ -177,6 +158,21 @@ public function skipsAuthorization()
177158
return false;
178159
}
179160

161+
/**
162+
* Determine if the client has the given grant type.
163+
*
164+
* @param string $grantType
165+
* @return bool
166+
*/
167+
public function hasGrantType($grantType)
168+
{
169+
if (! isset($this->attributes['grant_types']) || ! is_array($this->grant_types)) {
170+
return true;
171+
}
172+
173+
return in_array($grantType, $this->grant_types);
174+
}
175+
180176
/**
181177
* Determine whether the client has the given scope.
182178
*
@@ -185,7 +181,7 @@ public function skipsAuthorization()
185181
*/
186182
public function hasScope($scope)
187183
{
188-
if (! is_array($this->scopes)) {
184+
if (! isset($this->attributes['scopes']) || ! is_array($this->scopes)) {
189185
return true;
190186
}
191187

tests/Feature/AccessTokenControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testGettingAccessTokenWithClientCredentialsGrant()
4949
$this->assertArrayHasKey('expires_in', $decodedResponse);
5050
$this->assertArrayHasKey('access_token', $decodedResponse);
5151
$this->assertSame('Bearer', $decodedResponse['token_type']);
52-
$expiresInSeconds = 31622400;
52+
$expiresInSeconds = 31536000;
5353
$this->assertEqualsWithDelta($expiresInSeconds, $decodedResponse['expires_in'], 5);
5454

5555
$token = $this->app->make(PersonalAccessTokenFactory::class)->findAccessToken($decodedResponse);
@@ -141,7 +141,7 @@ public function testGettingAccessTokenWithPasswordGrant()
141141
$this->assertArrayHasKey('access_token', $decodedResponse);
142142
$this->assertArrayHasKey('refresh_token', $decodedResponse);
143143
$this->assertSame('Bearer', $decodedResponse['token_type']);
144-
$expiresInSeconds = 31622400;
144+
$expiresInSeconds = 31536000;
145145
$this->assertEqualsWithDelta($expiresInSeconds, $decodedResponse['expires_in'], 5);
146146

147147
$token = $this->app->make(PersonalAccessTokenFactory::class)->findAccessToken($decodedResponse);

tests/Feature/ClientTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace Laravel\Passport\Tests\Feature;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Laravel\Passport\Client;
7+
use Orchestra\Testbench\TestCase;
8+
9+
final class ClientTest extends TestCase
10+
{
11+
protected function setUp(): void
12+
{
13+
parent::setUp();
14+
15+
Model::preventAccessingMissingAttributes();
16+
}
17+
18+
protected function tearDown(): void
19+
{
20+
Model::preventAccessingMissingAttributes(false);
21+
22+
parent::tearDown();
23+
}
24+
25+
public function testScopesWhenClientDoesNotHaveScope(): void
26+
{
27+
$client = new Client(['scopes' => ['bar']]);
28+
$client->exists = true;
29+
30+
$this->assertFalse($client->hasScope('foo'));
31+
}
32+
33+
public function testScopesWhenClientHasScope(): void
34+
{
35+
$client = new Client(['scopes' => ['foo', 'bar']]);
36+
$client->exists = true;
37+
38+
$this->assertTrue($client->hasScope('foo'));
39+
}
40+
41+
public function testScopesWhenColumnDoesNotExist(): void
42+
{
43+
$client = new Client();
44+
$client->exists = true;
45+
46+
$this->assertTrue($client->hasScope('foo'));
47+
}
48+
49+
public function testScopesWhenColumnIsNull(): void
50+
{
51+
$client = new Client(['scopes' => null]);
52+
$client->exists = true;
53+
54+
$this->assertTrue($client->hasScope('foo'));
55+
}
56+
57+
public function testGrantTypesWhenClientDoesNotHaveGrantType(): void
58+
{
59+
$client = new Client(['grant_types' => ['bar']]);
60+
$client->exists = true;
61+
62+
$this->assertFalse($client->hasGrantType('foo'));
63+
}
64+
65+
public function testGrantTypesWhenClientHasGrantType(): void
66+
{
67+
$client = new Client(['grant_types' => ['foo', 'bar']]);
68+
$client->exists = true;
69+
70+
$this->assertTrue($client->hasGrantType('foo'));
71+
}
72+
73+
public function testGrantTypesWhenColumnDoesNotExist(): void
74+
{
75+
$client = new Client();
76+
$client->exists = true;
77+
78+
$this->assertTrue($client->hasGrantType('foo'));
79+
}
80+
81+
public function testGrantTypesWhenColumnIsNull(): void
82+
{
83+
$client = new Client(['scopes' => null]);
84+
$client->exists = true;
85+
86+
$this->assertTrue($client->hasGrantType('foo'));
87+
}
88+
}

tests/Unit/BridgeClientRepositoryTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,13 @@ public function confidential()
207207
{
208208
return ! empty($this->secret);
209209
}
210+
211+
public function hasGrantType($grantType)
212+
{
213+
if (! isset($this->grant_types) || ! is_array($this->grant_types)) {
214+
return true;
215+
}
216+
217+
return in_array($grantType, $this->grant_types);
218+
}
210219
}

0 commit comments

Comments
 (0)