Skip to content

Commit 246ea67

Browse files
committed
Merge remote-tracking branch 'origin/9.next' into 11.next-cake4
2 parents da871a5 + d6b45a1 commit 246ea67

31 files changed

+2805
-275
lines changed

.semver

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
:major: 9
3-
:minor: 2
2+
:major: 11
3+
:minor: 0
44
:patch: 0
55
:special: ''

Docs/Documentation/Authentication.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ Authentication
22
==============
33
This plugin uses the new authentication plugin [cakephp/authentication](https://github.com/cakephp/authentication/)
44
instead of CakePHP Authentication component, but don't worry, the default configuration should be enough for your
5-
projects.
5+
projects.
66

77
We've tried to simplify configuration as much as possible using defaults, but keep the ability to override them when needed.
88

99
Authentication Component
1010
------------------------
1111

12-
The default behavior is to load the authentication component at UsersController,
13-
defining the default urls for loginAction, loginRedirect, logoutRedirect but not requiring
12+
The default behavior is to load the authentication component at UsersController,
13+
defining the default urls for loginAction, loginRedirect, logoutRedirect but not requiring
1414
the request to have a identity.
1515

1616
If you prefer to load the component yourself you can set 'Auth.AuthenticationComponent.load':
@@ -29,7 +29,7 @@ $user = $this->Authentication->getIdentity()->getOriginalData();
2929
```
3030
The default configuration for Auth.AuthenticationComponent is:
3131

32-
```
32+
```php
3333
[
3434
'load' => true,
3535
'loginRedirect' => '/',
@@ -57,25 +57,23 @@ list of authenticators includes:
5757

5858
These authenticators should be enough for your application, but you easily customize it
5959
setting the Auth.Authenticators config key.
60-
61-
For example if you add JWT authenticator you can set:
6260

63-
```
64-
$authenticators = Configure::read('Auth.Authenticators');
65-
$authenticators['Jwt'] = [
66-
'className' => 'Authentication.Jwt',
61+
For example if you add JWT authenticator you must add this to your config/users.php file:
62+
63+
```php
64+
'Auth.Authenticators.Jwt' => [
6765
'queryParam' => 'token',
6866
'skipTwoFactorVerify' => true,
69-
];
70-
Configure::write('Auth.Authenticators', $authenticators);
67+
'className' => 'Authentication.Jwt',
68+
],
69+
```
7170

72-
```
7371
**You may have noticed the 'skipTwoFactorVerify' option, this option is used to identify if a authenticator should skip
7472
the two factor flow**
7573

7674
The authenticators are loaded by \CakeDC\Users\Loader\AuthenticationServiceLoader class at load authentication
7775
service method from plugin object.
78-
76+
7977
See the full Auth.Authenticators at config/users.php
8078

8179
Identifiers
@@ -86,11 +84,12 @@ The identifies are defined to work correctly with the default authenticators, we
8684
- CakeDC/Users.Social, for Social and SocialPendingEmail authenticators
8785
- Authentication.Token, for TokenAuthenticator
8886

89-
As you add more authenticators you may need to add identifiers, please check identifiers available at
87+
As you add more authenticators you may need to add identifiers, please check identifiers available at
9088
[official documentation](https://github.com/cakephp/authentication/blob/master/docs/Identifiers.md)
9189

9290
The default value for Auth.Identifiers is:
93-
```
91+
92+
```php
9493
[
9594
'Password' => [
9695
'className' => 'Authentication.Password',
@@ -127,14 +126,15 @@ For both form login and social login we use a base component 'CakeDC/Users.Login
127126
it check the result of authentication service to redirect user to a internal page or show an authentication
128127
error. It provide some error messages for specific authentication result status, please check the config/users.php file.
129128

130-
To use a custom component to handle the login you could do:
129+
To use a custom component to handle the login you should update your config/users.php file with:
130+
131+
```php
132+
'Auth.SocialLoginFailure.component' => 'MyLoginA',
133+
'Auth.FormLoginFailure.component' => 'MyLoginB',
131134
```
132-
Configure::write('Auth.SocialLoginFailure.component', 'MyLoginA');
133-
Configure::write('Auth.FormLoginFailure.component', 'MyLoginB');
134-
```
135135

136136
The default configuration are:
137-
```
137+
```php
138138
[
139139
...
140140
'Auth' => [
@@ -165,24 +165,24 @@ The default configuration are:
165165
...
166166
]
167167
]
168-
```
168+
```
169169

170-
Authentication Service Loader
170+
Authentication Service Loader
171171
-----------------------------
172172
To make the integration with cakephp/authentication easier we load the authenticators and identifiers
173173
defined at Auth configuration and other components to work with social provider, two-factor authentication.
174174

175-
If the configuration is not enough for your project you may create a custom loader extending the
175+
If the configuration is not enough for your project you may create a custom loader extending the
176176
default provided.
177177

178178
- Create file src/Loader/AppAuthenticationServiceLoader.php
179179

180-
```
180+
```php
181181
<?php
182182
namespace App\Loader;
183-
183+
184184
use \CakeDC\Users\Loader\AuthenticationServiceLoader;
185-
185+
186186
class AppAuthenticationServiceLoader extends AuthenticationServiceLoader
187187
{
188188
/**
@@ -202,8 +202,8 @@ class AppAuthenticationServiceLoader extends AuthenticationServiceLoader
202202
}
203203
}
204204
```
205-
- Change the authentication service loader:
205+
- Add this to your config/users.php file to change the authentication service loader:
206206

207-
```
208-
Configure::write('Authentication.serviceLoader', \App\Loader\AuthenticationServiceLoader::class);
207+
```php
208+
'Auth.Authentication.serviceLoader' => \App\Loader\AuthenticationServiceLoader::class,
209209
```

Docs/Documentation/Authorization.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@ projects. We tried to allow you to start quickly without the need to configure a
66
allow you to configure as much as possible.
77

88

9-
If you don't want the plugin to autoload setup authorization, you can do:
10-
```
11-
Configure::write('Auth.Authorization.enabled', false);
9+
If you don't want the plugin to autoload setup authorization, you can disable
10+
in your config/users.php with:
11+
12+
```php
13+
'Auth.Authorization.enabled' => false,
1214
```
1315

1416
Authorization Middleware
1517
------------------------
1618
We load the RequestAuthorization and Authorization middleware with OrmResolver and RbacProvider(work with RequestAuthorizationMiddleware).
1719

18-
The middleware accepts some additional configurations, you can do:
19-
```
20-
Configure::write('Auth.AuthorizationMiddleware', $config);
20+
The middleware accepts some additional configurations, you can update in your
21+
config/users.php file:
22+
```php
23+
'Auth.AuthorizationMiddleware' => $config,
2124
```
2225

2326
The default configuration for authorization middleware is:
24-
```
27+
```php
2528
[
2629
'unauthorizedHandler' => [
2730
'className' => 'CakeDC/Users.DefaultRedirect',
@@ -41,7 +44,7 @@ The `CakeDC/Users.DefaultRedirect` offers additional behavior and config:
4144

4245
You could do the following to set a custom url and flash message:
4346

44-
```
47+
```php
4548
[
4649
'unauthorizedHandler' => [
4750
'className' => 'CakeDC/Users.DefaultRedirect',
@@ -61,7 +64,7 @@ You could do the following to set a custom url and flash message:
6164
],
6265
```
6366
OR
64-
```
67+
```php
6568
[
6669
'unauthorizedHandler' => [
6770
'className' => 'CakeDC/Users.DefaultRedirect',
@@ -82,9 +85,10 @@ OR
8285
Authorization Component
8386
-----------------------
8487
We autoload the authorization component at users controller using the default configuration,
85-
if you don't want the plugin to autoload it, you can do:
86-
```
87-
Configure::write('Auth.AuthorizationComponent.enabled', false);
88+
if you don't want the plugin to autoload it, you can add this to your config/users.php file:
89+
90+
```php
91+
'Auth.AuthorizationComponent.enabled' => false,
8892
```
8993

9094
You can check the configuration options available for authorization component at the
@@ -100,7 +104,7 @@ default provided.
100104

101105
- Create file src/Loader/AppAuthorizationServiceLoader.php
102106

103-
```
107+
```php
104108
<?php
105109
namespace App\Loader;
106110

@@ -127,8 +131,8 @@ class AppAuthorizationServiceLoader
127131
}
128132
}
129133
```
130-
- Change the authorization service loader:
134+
- Add this to your config/users.php file to change the authorization service loader:
131135

132-
```
133-
Configure::write('Auth.Authorization.serviceLoader', \App\Loader\AppAuthorizationServiceLoader::class);
136+
```php
137+
'Auth.Authorization.serviceLoader' => \App\Loader\AppAuthorizationServiceLoader::class,
134138
```

Docs/Documentation/Configuration.md

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ Overriding the default configuration
66

77
For easier configuration, you can specify an array of config files to override the default plugin keys this way:
88

9-
config/bootstrap.php
9+
Make sure you loaded the plugin and is using a custom config/users.php file at Application::bootstrap
1010
```
1111
// The following configuration setting must be set before loading the Users plugin
12+
$this->addPlugin(\CakeDC\Users\Plugin::class);
1213
Configure::write('Users.config', ['users']);
13-
Plugin::load('CakeDC/Users', ['routes' => true, 'bootstrap' => true]);
14-
Configure::write('Users.Social.login', true); //to enable social login
1514
```
1615

1716
Configuration for social login
@@ -28,13 +27,14 @@ $ composer require league/oauth1-client:@stable
2827

2928
NOTE: twitter uses league/oauth1-client package
3029

31-
config/bootstrap.php
32-
```
33-
Configure::write('OAuth.providers.facebook.options.clientId', 'YOUR APP ID');
34-
Configure::write('OAuth.providers.facebook.options.clientSecret', 'YOUR APP SECRET');
30+
And update your config/users.php file:
3531

36-
Configure::write('OAuth.providers.twitter.options.clientId', 'YOUR APP ID');
37-
Configure::write('OAuth.providers.twitter.options.clientSecret', 'YOUR APP SECRET');
32+
```php
33+
'Users.Social.login' => true,
34+
'OAuth.providers.facebook.options.clientId' => 'YOUR APP ID',
35+
'OAuth.providers.facebook.options.clientSecret' => 'YOUR APP SECRET',
36+
'OAuth.providers.twitter.options.clientId' => 'YOUR APP ID',
37+
'OAuth.providers.twitter.options.clientSecret' => 'YOUR APP SECRET',
3838
```
3939

4040
Or use the config override option when loading the plugin (see above)
@@ -44,15 +44,18 @@ Additionally you will see you can configure two more keys for each provider:
4444
* linkSocialUri (default: /link-social/**provider**),
4545
* callbackLinkSocialUri(default: /callback-link-social/**provider**)
4646

47-
Those keys are needed to link an existing user account to a third-party account. **Remember to add the callback to your thrid-party app**
47+
Those keys are needed to link an existing user account to a third-party account. **Remember to add the callback to your thrid-party app**
4848

4949
Configuration for reCaptcha
5050
---------------------
51-
```
52-
Configure::write('Users.reCaptcha.key', 'YOUR RECAPTCHA KEY');
53-
Configure::write('Users.reCaptcha.secret', 'YOUR RECAPTCHA SECRET');
54-
Configure::write('Users.reCaptcha.registration', true); //enable on registration
55-
Configure::write('Users.reCaptcha.login', true); //enable on login
51+
To enable reCaptcha you need to register your site at google reCaptcha console
52+
and add this to your config/users.php file:
53+
54+
```php
55+
'Users.reCaptcha.key' => 'YOUR RECAPTCHA KEY',
56+
'Users.reCaptcha.secret' => 'YOUR RECAPTCHA SECRET',
57+
'Users.reCaptcha.registration' => true, //enable on registration
58+
'Users.reCaptcha.login' => true, //enable on login
5659
```
5760

5861

@@ -70,10 +73,11 @@ and [cakephp/authorization](https://github.com/cakephp/authorization) plugins we
7073
into their documentation for more information.
7174

7275
Most authentication/authorization configuration is defined at 'Auth' key, for example
73-
if you don't want the plugin to autoload the authorization service, you could do:
76+
if you don't want the plugin to autoload the authorization service, you could add this
77+
to your config/users.php file:
7478

7579
```
76-
Configure::write('Auth.Authorization.enable', false)
80+
'Auth.Authorization.enable' => false,
7781
```
7882

7983
Interesting Users options and defaults
@@ -163,25 +167,17 @@ To learn more about it please check the configurations for [Authentication](Auth
163167

164168
You need to configure 2 things (version 9.0.4):
165169

166-
* Change the Password identifier fields and the Authenticator for Forms configuration to let it use the email instead of the username for user identify. Add this to your Application class, right before CakeDC/Users Plugin is loaded.
170+
* Change the Password identifier fields and the Authenticator for Forms
171+
configuration to let it use the email instead of the username for
172+
user identify. Add this to your config/users.php:
167173

168174
```php
169-
// Load more plugins here
170-
$identifiers = Configure::read('Auth.Identifiers');
171-
$identifiers['Password']['fields']['username'] = 'email';
172-
Configure::write('Auth.Identifiers', $identifiers);
173-
174-
$authenticators = Configure::read('Auth.Authenticators');
175-
$authenticators['Form']['fields']['username'] = 'email';
176-
Configure::write('Auth.Authenticators', $authenticators);
177-
178-
//Configure::write('Users.config', ['users', 'permissions']);
179-
180-
$this->addPlugin(\CakeDC\Users\Plugin::class);
175+
'Auth.Identifiers.Password.fields.username' => 'email',
176+
'Auth.Authenticators.Form.fields.username' => 'email',
181177
```
182178

183-
* Override the login.php template to change the Form->control to "email".
184-
Add (or copy from the [/templates/Users/login.php](../../templates/Users/login.php)) the file login.php to path /templates/plugin/CakeDC/Users/Users/login.php
179+
* Override the login.php template to change the Form->control to "email".
180+
Add (or copy from the [/templates/Users/login.php](../../templates/Users/login.php)) the file login.php to path /templates/plugin/CakeDC/Users/Users/login.php
185181
and ensure it has the following content
186182

187183
```php

0 commit comments

Comments
 (0)