|
| 1 | +Upgrade Guide 3.x to 4.x |
| 2 | +######################### |
| 3 | + |
| 4 | +Version 4.0 is a major release with several breaking changes focused on |
| 5 | +simplifying the API and removing deprecated code. |
| 6 | + |
| 7 | +Breaking Changes |
| 8 | +================ |
| 9 | + |
| 10 | +IdentifierCollection Removed |
| 11 | +----------------------------- |
| 12 | + |
| 13 | +The deprecated ``IdentifierCollection`` has been removed. Authenticators now |
| 14 | +accept a nullable ``IdentifierInterface`` directly. |
| 15 | + |
| 16 | +**Before (3.x):** |
| 17 | + |
| 18 | +.. code-block:: php |
| 19 | +
|
| 20 | + use Authentication\Identifier\IdentifierCollection; |
| 21 | +
|
| 22 | + $identifiers = new IdentifierCollection([ |
| 23 | + 'Authentication.Password', |
| 24 | + ]); |
| 25 | +
|
| 26 | + $authenticator = new FormAuthenticator($identifiers); |
| 27 | +
|
| 28 | +**After (4.x):** |
| 29 | + |
| 30 | +.. code-block:: php |
| 31 | +
|
| 32 | + use Authentication\Identifier\IdentifierFactory; |
| 33 | +
|
| 34 | + // Option 1: Pass identifier directly |
| 35 | + $identifier = IdentifierFactory::create('Authentication.Password'); |
| 36 | + $authenticator = new FormAuthenticator($identifier); |
| 37 | +
|
| 38 | + // Option 2: Pass null and let authenticator create default |
| 39 | + $authenticator = new FormAuthenticator(null); |
| 40 | +
|
| 41 | + // Option 3: Configure identifier in authenticator config |
| 42 | + $service->loadAuthenticator('Authentication.Form', [ |
| 43 | + 'identifier' => 'Authentication.Password', |
| 44 | + ]); |
| 45 | +
|
| 46 | +AuthenticationService Changes |
| 47 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 48 | + |
| 49 | +The ``loadIdentifier()`` method has been removed from ``AuthenticationService``. |
| 50 | +Identifiers are now managed by individual authenticators. |
| 51 | + |
| 52 | +**Before (3.x):** |
| 53 | + |
| 54 | +.. code-block:: php |
| 55 | +
|
| 56 | + $service = new AuthenticationService(); |
| 57 | + $service->loadIdentifier('Authentication.Password'); |
| 58 | + $service->loadAuthenticator('Authentication.Form'); |
| 59 | +
|
| 60 | +**After (4.x):** |
| 61 | + |
| 62 | +.. code-block:: php |
| 63 | +
|
| 64 | + $service = new AuthenticationService(); |
| 65 | + $service->loadAuthenticator('Authentication.Form', [ |
| 66 | + 'identifier' => 'Authentication.Password', |
| 67 | + ]); |
| 68 | +
|
| 69 | +CREDENTIAL Constants Moved |
| 70 | +--------------------------- |
| 71 | + |
| 72 | +The ``CREDENTIAL_USERNAME`` and ``CREDENTIAL_PASSWORD`` constants have been |
| 73 | +moved from ``AbstractIdentifier`` to specific identifier implementations. |
| 74 | + |
| 75 | +**Before (3.x):** |
| 76 | + |
| 77 | +.. code-block:: php |
| 78 | +
|
| 79 | + use Authentication\Identifier\AbstractIdentifier; |
| 80 | +
|
| 81 | + $fields = [ |
| 82 | + AbstractIdentifier::CREDENTIAL_USERNAME => 'email', |
| 83 | + AbstractIdentifier::CREDENTIAL_PASSWORD => 'password', |
| 84 | + ]; |
| 85 | +
|
| 86 | +**After (4.x):** |
| 87 | + |
| 88 | +.. code-block:: php |
| 89 | +
|
| 90 | + use Authentication\Identifier\PasswordIdentifier; |
| 91 | +
|
| 92 | + $fields = [ |
| 93 | + PasswordIdentifier::CREDENTIAL_USERNAME => 'email', |
| 94 | + PasswordIdentifier::CREDENTIAL_PASSWORD => 'password', |
| 95 | + ]; |
| 96 | +
|
| 97 | +For LDAP authentication: |
| 98 | + |
| 99 | +.. code-block:: php |
| 100 | +
|
| 101 | + use Authentication\Identifier\LdapIdentifier; |
| 102 | +
|
| 103 | + $fields = [ |
| 104 | + LdapIdentifier::CREDENTIAL_USERNAME => 'uid', |
| 105 | + LdapIdentifier::CREDENTIAL_PASSWORD => 'password', |
| 106 | + ]; |
| 107 | +
|
| 108 | +URL Checker Renamed |
| 109 | +------------------- |
| 110 | + |
| 111 | +``CakeRouterUrlChecker`` has been renamed to ``CakeUrlChecker`` and now accepts |
| 112 | +both string and array URLs (just like ``Router::url()``). |
| 113 | + |
| 114 | +**Before (3.x):** |
| 115 | + |
| 116 | +.. code-block:: php |
| 117 | +
|
| 118 | + $service->loadAuthenticator('Authentication.Form', [ |
| 119 | + 'urlChecker' => 'Authentication.CakeRouter', |
| 120 | + 'loginUrl' => [ |
| 121 | + 'controller' => 'Users', |
| 122 | + 'action' => 'login', |
| 123 | + ], |
| 124 | + ]); |
| 125 | +
|
| 126 | +**After (4.x):** |
| 127 | + |
| 128 | +.. code-block:: php |
| 129 | +
|
| 130 | + // CakeUrlChecker is now the default when CakePHP is installed |
| 131 | + $service->loadAuthenticator('Authentication.Form', [ |
| 132 | + 'loginUrl' => [ |
| 133 | + 'controller' => 'Users', |
| 134 | + 'action' => 'login', |
| 135 | + ], |
| 136 | + ]); |
| 137 | +
|
| 138 | + // Or explicitly: |
| 139 | + $service->loadAuthenticator('Authentication.Form', [ |
| 140 | + 'urlChecker' => 'Authentication.Cake', |
| 141 | + 'loginUrl' => [ |
| 142 | + 'controller' => 'Users', |
| 143 | + 'action' => 'login', |
| 144 | + ], |
| 145 | + ]); |
| 146 | +
|
| 147 | +Simplified URL Checker API |
| 148 | +--------------------------- |
| 149 | + |
| 150 | +URL checkers now accept a single URL in either string or array format. |
| 151 | +For multiple URLs, you must explicitly use ``MultiUrlChecker``. |
| 152 | + |
| 153 | +**Multiple URLs - Before (3.x):** |
| 154 | + |
| 155 | +.. code-block:: php |
| 156 | +
|
| 157 | + // This would auto-select the appropriate checker |
| 158 | + $service->loadAuthenticator('Authentication.Form', [ |
| 159 | + 'loginUrl' => [ |
| 160 | + '/en/users/login', |
| 161 | + '/de/users/login', |
| 162 | + ], |
| 163 | + ]); |
| 164 | +
|
| 165 | +**Multiple URLs - After (4.x):** |
| 166 | + |
| 167 | +.. code-block:: php |
| 168 | +
|
| 169 | + // Must explicitly configure MultiUrlChecker |
| 170 | + $service->loadAuthenticator('Authentication.Form', [ |
| 171 | + 'urlChecker' => 'Authentication.Multi', |
| 172 | + 'loginUrl' => [ |
| 173 | + '/en/users/login', |
| 174 | + '/de/users/login', |
| 175 | + ], |
| 176 | + ]); |
| 177 | +
|
| 178 | +Single URLs work the same in both versions: |
| 179 | + |
| 180 | +.. code-block:: php |
| 181 | +
|
| 182 | + // String URL |
| 183 | + $service->loadAuthenticator('Authentication.Form', [ |
| 184 | + 'loginUrl' => '/users/login', |
| 185 | + ]); |
| 186 | +
|
| 187 | + // Array URL (CakePHP route) |
| 188 | + $service->loadAuthenticator('Authentication.Form', [ |
| 189 | + 'loginUrl' => ['controller' => 'Users', 'action' => 'login'], |
| 190 | + ]); |
| 191 | +
|
| 192 | +Auto-Detection Changes |
| 193 | +---------------------- |
| 194 | + |
| 195 | +URL Checkers |
| 196 | +^^^^^^^^^^^^ |
| 197 | + |
| 198 | +- When CakePHP Router is available: defaults to ``CakeUrlChecker`` |
| 199 | +- Without CakePHP: defaults to ``DefaultUrlChecker`` |
| 200 | +- For multiple URLs: you **must** explicitly configure ``MultiUrlChecker`` |
| 201 | + |
| 202 | +DefaultUrlChecker Changes |
| 203 | +^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 204 | + |
| 205 | +``DefaultUrlChecker`` no longer accepts array-based URLs. It throws a |
| 206 | +``RuntimeException`` if an array URL is provided: |
| 207 | + |
| 208 | +.. code-block:: php |
| 209 | +
|
| 210 | + // This will throw an exception in 4.x |
| 211 | + $checker = new DefaultUrlChecker(); |
| 212 | + $checker->check($request, ['controller' => 'Users', 'action' => 'login']); |
| 213 | +
|
| 214 | + // Use CakeUrlChecker instead: |
| 215 | + $checker = new CakeUrlChecker(); |
| 216 | + $checker->check($request, ['controller' => 'Users', 'action' => 'login']); |
| 217 | +
|
| 218 | +New Features |
| 219 | +============ |
| 220 | + |
| 221 | +IdentifierFactory |
| 222 | +----------------- |
| 223 | + |
| 224 | +New factory class for creating identifiers from configuration: |
| 225 | + |
| 226 | +.. code-block:: php |
| 227 | +
|
| 228 | + use Authentication\Identifier\IdentifierFactory; |
| 229 | +
|
| 230 | + // Create from string |
| 231 | + $identifier = IdentifierFactory::create('Authentication.Password'); |
| 232 | +
|
| 233 | + // Create with config |
| 234 | + $identifier = IdentifierFactory::create('Authentication.Password', [ |
| 235 | + 'fields' => [ |
| 236 | + 'username' => 'email', |
| 237 | + 'password' => 'password', |
| 238 | + ], |
| 239 | + ]); |
| 240 | +
|
| 241 | + // Pass existing instance (returns as-is) |
| 242 | + $identifier = IdentifierFactory::create($existingIdentifier); |
| 243 | +
|
| 244 | +MultiUrlChecker |
| 245 | +--------------- |
| 246 | + |
| 247 | +New dedicated checker for multiple login URLs: |
| 248 | + |
| 249 | +.. code-block:: php |
| 250 | +
|
| 251 | + $service->loadAuthenticator('Authentication.Form', [ |
| 252 | + 'urlChecker' => 'Authentication.Multi', |
| 253 | + 'loginUrl' => [ |
| 254 | + '/en/login', |
| 255 | + '/de/login', |
| 256 | + ['lang' => 'fr', 'controller' => 'Users', 'action' => 'login'], |
| 257 | + ], |
| 258 | + ]); |
| 259 | +
|
| 260 | +Migration Tips |
| 261 | +============== |
| 262 | + |
| 263 | +1. **Search and Replace**: |
| 264 | + |
| 265 | + - ``AbstractIdentifier::CREDENTIAL_`` → ``PasswordIdentifier::CREDENTIAL_`` |
| 266 | + - ``IdentifierCollection`` → ``IdentifierFactory`` |
| 267 | + - ``'Authentication.CakeRouter'`` → ``'Authentication.Cake'`` |
| 268 | + - ``CakeRouterUrlChecker`` → ``CakeUrlChecker`` |
| 269 | + |
| 270 | +2. **Multiple Login URLs**: |
| 271 | + |
| 272 | + If you have multiple login URLs, add ``'urlChecker' => 'Authentication.Multi'`` |
| 273 | + to your authenticator configuration. |
| 274 | + |
| 275 | +3. **Custom Identifier Setup**: |
| 276 | + |
| 277 | + If you were passing ``IdentifierCollection`` to authenticators, switch to |
| 278 | + either passing a single identifier or null (to use defaults). |
| 279 | + |
| 280 | +4. **Test Thoroughly**: |
| 281 | + |
| 282 | + The changes to identifier management and URL checking are significant. |
| 283 | + Test all authentication flows after upgrading. |
0 commit comments