Skip to content

Commit e6914f6

Browse files
authored
Merge pull request #18 from nojimage/update-php8.4-cake5.2
Support PHP 8.4, CakePHP 5.2
2 parents 43bd7da + 968a96a commit e6914f6

10 files changed

Lines changed: 81 additions & 63 deletions

File tree

.github/workflows/ci.yml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ on:
1212

1313
jobs:
1414
testsuite:
15-
runs-on: ubuntu-22.04
15+
runs-on: ubuntu-24.04
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
cakephp-version: ['5.0.*']
20-
php-version: ['8.1', '8.2', '8.3']
19+
cakephp-version: ['5.0.*', '5.1.*', '5.2.*']
20+
php-version: ['8.2', '8.3', '8.4']
2121
db-type: ['mysql']
2222
prefer-lowest: ['']
2323
coverage: ['no']
@@ -27,14 +27,14 @@ jobs:
2727
db-type: 'mysql:8.0'
2828
prefer-lowest: 'prefer-lowest'
2929
coverage: 'no'
30-
- cakephp-version: '5.0.*'
31-
php-version: '8.3'
30+
- cakephp-version: '5.2.*'
31+
php-version: '8.4'
3232
db-type: 'mysql'
3333
prefer-lowest: ''
3434
coverage: 'no'
3535

36-
- php-version: '8.3'
37-
cakephp-version: '5.0.*'
36+
- php-version: '8.4'
37+
cakephp-version: '5.2.*'
3838
db-type: 'mysql'
3939
prefer-lowest: ''
4040
coverage: 'coverage'
@@ -80,9 +80,7 @@ jobs:
8080
8181
- name: Composer install
8282
run: |
83-
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
84-
composer update --ignore-platform-reqs
85-
elif ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
83+
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
8684
composer update --prefer-lowest --prefer-stable
8785
else
8886
composer update
@@ -111,7 +109,7 @@ jobs:
111109

112110
cs-stan:
113111
name: Coding Standard & Static Analysis
114-
runs-on: ubuntu-22.04
112+
runs-on: ubuntu-24.04
115113

116114
steps:
117115
- uses: actions/checkout@v4
@@ -121,7 +119,7 @@ jobs:
121119
- name: Setup PHP
122120
uses: shivammathur/setup-php@v2
123121
with:
124-
php-version: '8.3'
122+
php-version: '8.4'
125123
extensions: mbstring, intl, apcu
126124
coverage: none
127125

@@ -152,6 +150,6 @@ jobs:
152150
# if: success() || failure()
153151
# run: vendor/bin/psalm.phar --output-format=github
154152
#
155-
# - name: Run phpstan
156-
# if: success() || failure()
157-
# run: vendor/bin/phpstan.phar analyse --error-format=github
153+
- name: Run phpstan
154+
if: success() || failure()
155+
run: vendor/bin/phpstan.phar analyse --error-format=github

README.ja.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
このプラグインは、Cookieによって永続的にログインする認証ハンドラを提供します。 暗号化されたユーザー名/パスワードをCookieに設定する代わりに、トークンを発行する方法を使用します。
1919

20-
This library inspired by Barry Jaspan's article "[Improved Persistent Login Cookie Best Practice](http://jaspan.com/improved_persistent_login_cookie_best_practice)", and Gabriel Birke's libray "https://github.com/gbirke/rememberme".
20+
This library is inspired by Barry Jaspan's article "[Improved Persistent Login Cookie Best Practice](http://jaspan.com/improved_persistent_login_cookie_best_practice)", and Gabriel Birke's library "https://github.com/gbirke/rememberme".
2121

2222
## インストール
2323

@@ -50,7 +50,7 @@ bin/cake migrations migrate -p RememberMe
5050
## Authenticationプラグインでの使用方法
5151

5252
[cakephp/authentication](https://github.com/cakephp/authentication) を使用しているのであれば、
53-
`RememberMeTokenIdentifier``CookeAuthenticator` を使用してください。
53+
`RememberMeTokenIdentifier``CookieAuthenticator` を使用してください。
5454

5555
`Application``getAuthenticationService` フックで RememberMeプラグインの Identifier と Authenticator を呼び出す例です:
5656

@@ -135,7 +135,7 @@ default: `'remember_me_token'`
135135
]);
136136
```
137137

138-
### RememberMe.CookeAuthenticator のオプション
138+
### RememberMe.CookieAuthenticator のオプション
139139

140140
#### `loginUrl`
141141

@@ -223,7 +223,7 @@ default: `'RememberMe.RememberMeTokens'`
223223

224224
#### `always`
225225

226-
このオプションをtrueに設定すると、ログインCookieは認証が識別された後、常に発行されます
226+
このオプションをtrueに設定すると、認証が成功した後、常にログインCookieが発行されます
227227

228228
default: `false`
229229

@@ -235,7 +235,7 @@ default: `false`
235235

236236
#### `dropExpiredToken`
237237

238-
このオプションをtrueに設定すると、認証が識別された後に有効期限が切れたトークンを削除します
238+
このオプションをtrueに設定すると、認証が成功した後に有効期限が切れたトークンを削除します
239239

240240
default: `true`
241241

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
</a>
1616
</p>
1717

18-
This plugin provides an authenticate handler that permanent login by cookie. This plugin use method of issuing a token, instead of set to cookie encrypted username/password.
18+
This plugin provides an authentication handler that enables permanent login via cookie. This plugin uses a method of issuing a token instead of setting an encrypted username / password in a cookie.
1919

20-
This library inspired by Barry Jaspan's article "[Improved Persistent Login Cookie Best Practice](http://jaspan.com/improved_persistent_login_cookie_best_practice)", and Gabriel Birke's libray "https://github.com/gbirke/rememberme".
20+
This library is inspired by Barry Jaspan's article "[Improved Persistent Login Cookie Best Practice](http://jaspan.com/improved_persistent_login_cookie_best_practice)", and Gabriel Birke's library "https://github.com/gbirke/rememberme".
2121

2222
## Installation
2323

@@ -50,9 +50,9 @@ bin/cake migrations migrate -p RememberMe
5050
## Usage with Authentication plugin
5151

5252
If you're using [cakephp/authentication](https://github.com/cakephp/authentication),
53-
use `RememberMeTokenIdentifier` and `CookeAuthenticator`.
53+
use `RememberMeTokenIdentifier` and `CookieAuthenticator`.
5454

55-
Example load RememberMe's Identifier and Authenticator into the `getAuthenticationService` hook within `Application`:
55+
Example of loading RememberMe's Identifier and Authenticator into the `getAuthenticationService` hook within `Application`:
5656

5757
```php
5858
// in your src/Application.php
@@ -97,8 +97,8 @@ default: `['username' => 'username']`
9797

9898
#### `resolver`
9999

100-
The identity resolver. If change your Resolver,
101-
must extend `Authentication\Identifier\Resolver\OrmResolver`.
100+
The identity resolver. If you change your Resolver,
101+
it must extend `Authentication\Identifier\Resolver\OrmResolver`.
102102

103103
default: `'Authentication.Orm'`
104104

@@ -113,7 +113,7 @@ default: `'Authentication.Orm'`
113113

114114
#### `tokenStorageModel`
115115

116-
A model used for find login cookie tokens.
116+
A model used for finding login cookie tokens.
117117

118118
default: `'RememberMe.RememberMeTokens'`
119119

@@ -223,7 +223,7 @@ default: `'RememberMe.RememberMeTokens'`
223223

224224
#### `always`
225225

226-
When this option is set to true, a login cookie is always issued after authentication identified.
226+
When this option is set to true, a login cookie is always issued after successful authentication.
227227

228228
default: `false`
229229

@@ -235,7 +235,7 @@ default: `false`
235235

236236
#### `dropExpiredToken`
237237

238-
When this option is set to true, drop expired tokens after authentication identified.
238+
When this option is set to true, expired tokens are dropped after successful authentication.
239239

240240
default: `true`
241241

composer.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"cakephp/cakephp": "^5.0",
2222
"cakephp/cakephp-codesniffer": "^5.1",
2323
"cakephp/migrations": "^4.0",
24-
"phpunit/phpunit": "^10.1"
24+
"phpstan/phpstan": "^1.12",
25+
"phpunit/phpunit": "^10.5.5 || ^11.1.3 || ^12.0.9"
2526
},
2627
"autoload": {
2728
"psr-4": {
@@ -36,8 +37,15 @@
3637
}
3738
},
3839
"scripts": {
40+
"check": [
41+
"@cs-check",
42+
"@stan",
43+
"@test"
44+
],
3945
"cs-check": "phpcs -p --extensions=php ./src ./tests",
4046
"cs-fix": "phpcbf -p --extensions=php ./src ./tests",
47+
"stan": "phpstan analyse",
48+
"test": "phpunit --colors=always",
4149
"update-lowest": "composer update --prefer-lowest --prefer-stable"
4250
},
4351
"config": {

phpstan.neon.dist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
level: 8
3+
checkMissingIterableValueType: false
4+
treatPhpDocTypesAsCertain: false
5+
paths:
6+
- src/
7+
excludePaths:
8+
- test_app/
9+
ignoreErrors:
10+
-
11+
identifier: missingType.generics

src/Authenticator/CookieAuthenticator.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function persistIdentity(ServerRequestInterface $request, ResponseInterfa
148148
$encryptedToken = static::encryptToken(
149149
$identity[$this->getConfig('fields.' . AbstractIdentifier::CREDENTIAL_USERNAME)],
150150
$token['series'],
151-
$token['token']
151+
$token['token'],
152152
);
153153
$cookie = $this->_createCookie($encryptedToken, $token['expires']);
154154

@@ -173,8 +173,13 @@ protected function _saveToken(ArrayAccess|array $identity, string $token): Entit
173173
throw new InvalidArgumentException('Can\'t detect user model');
174174
}
175175

176-
$userTable = $this->fetchTable($userModel);
177-
/** @var \RememberMe\Model\Table\RememberMeTokensTableInterface $tokenTable */
176+
$usersTable = $this->fetchTable($userModel);
177+
$primaryKey = $usersTable->getPrimaryKey();
178+
if (!is_string($primaryKey)) {
179+
throw new InvalidArgumentException('User model must have a single primary key.');
180+
}
181+
182+
/** @var \RememberMe\Model\Table\RememberMeTokensTableInterface&\Cake\ORM\Table $tokenTable */
178183
$tokenTable = $this->fetchTable($this->getConfig('tokenStorageModel'));
179184

180185
if ($this->getConfig('dropExpiredToken')) {
@@ -185,7 +190,7 @@ protected function _saveToken(ArrayAccess|array $identity, string $token): Entit
185190
// create token entity
186191
$entity = $tokenTable->newEntity([
187192
'model' => $userModel,
188-
'foreign_id' => $identity[$userTable->getPrimaryKey()],
193+
'foreign_id' => $identity[$primaryKey],
189194
'series' => static::_generateToken($identity),
190195
'token' => $token,
191196
'expires' => new DateTime($this->getConfig('cookie.expire')),
@@ -261,7 +266,7 @@ protected function _createCookie(string $value, ?DateTime $expires = null): Cook
261266
$data['path'],
262267
$data['domain'],
263268
$data['secure'],
264-
$data['httpOnly']
269+
$data['httpOnly'],
265270
);
266271
}
267272

src/Authenticator/EncryptCookieTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public static function encryptToken(string $username, string $series, string $to
4444
return base64_encode(
4545
Security::encrypt(
4646
json_encode(compact('username', 'series', 'token'), JSON_THROW_ON_ERROR),
47-
Security::getSalt()
48-
)
47+
Security::getSalt(),
48+
),
4949
);
5050
}
5151

src/Identifier/RememberMeTokenIdentifier.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class RememberMeTokenIdentifier extends AbstractIdentifier
5050
/**
5151
* @inheritDoc
5252
*/
53-
protected function buildResolver($config): OrmResolver
53+
protected function buildResolver(array|string $config): OrmResolver
5454
{
5555
$instance = $this->traitBuildResolver($config);
5656

@@ -71,7 +71,7 @@ public function identify(array $credentials): ArrayAccess|array|null
7171
!isset(
7272
$credentials[self::CREDENTIAL_USERNAME],
7373
$credentials[self::CREDENTIAL_SERIES],
74-
$credentials[self::CREDENTIAL_TOKEN]
74+
$credentials[self::CREDENTIAL_TOKEN],
7575
)
7676
) {
7777
return null;
@@ -118,10 +118,10 @@ protected function _findIdentity(string $identifier): ArrayAccess|array|EntityIn
118118
}
119119

120120
/**
121-
* find user's remember me token.
121+
* find some user's remember me token.
122122
*
123123
* @param \Cake\Datasource\EntityInterface $identity the identity
124-
* @param string $series the credentials series
124+
* @param string $series the credential series
125125
* @return \Cake\Datasource\EntityInterface|null
126126
*/
127127
protected function _findToken(EntityInterface $identity, string $series): ?EntityInterface
@@ -133,11 +133,15 @@ protected function _findToken(EntityInterface $identity, string $series): ?Entit
133133

134134
$usersTable = $this->getResolver()->fetchTable($userModel);
135135
$tokenStorageTable = $this->getResolver()->fetchTable($this->getConfig('tokenStorageModel'));
136+
$primaryKey = $usersTable->getPrimaryKey();
137+
if (!is_string($primaryKey)) {
138+
throw new InvalidArgumentException('User model must have a single primary key.');
139+
}
136140

137141
return $tokenStorageTable->find()
138142
->where([
139143
'model' => $userModel,
140-
'foreign_id' => $identity->get($usersTable->getPrimaryKey()),
144+
'foreign_id' => $identity->get($primaryKey),
141145
'series' => $series,
142146
])
143147
->first();

src/Model/Entity/RememberMeToken.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,15 @@
2020
class RememberMeToken extends Entity
2121
{
2222
/**
23-
* Fields that can be mass assigned using newEntity() or patchEntity().
24-
*
25-
* Note that when '*' is set to true, this allows all unspecified fields to
26-
* be mass assigned. For security purposes, it is advised to set '*' to false
27-
* (or remove it), and explicitly make individual fields accessible as needed.
28-
*
29-
* @var array
23+
* @inheritDoc
3024
*/
3125
protected array $_accessible = [
3226
'*' => true,
3327
'id' => false,
3428
];
3529

3630
/**
37-
* Fields that are excluded from JSON versions of the entity.
38-
*
39-
* @var array
31+
* @inheritDoc
4032
*/
4133
protected array $_hidden = [
4234
'token',

0 commit comments

Comments
 (0)