File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 14
14
namespace CakeDC \Auth \Authentication ;
15
15
16
16
use Authentication \AuthenticationService as BaseService ;
17
+ use Authentication \Authenticator \Result ;
17
18
use Authentication \Authenticator \ResultInterface ;
18
19
use Authentication \Authenticator \StatelessInterface ;
19
20
use Cake \Datasource \EntityInterface ;
20
21
use Psr \Http \Message \ServerRequestInterface ;
21
22
use RuntimeException ;
23
+ use UnexpectedValueException ;
22
24
23
25
class AuthenticationService extends BaseService
24
26
{
@@ -71,6 +73,9 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
71
73
foreach ($ this ->authenticators () as $ authenticator ) {
72
74
$ result = $ authenticator ->authenticate ($ request );
73
75
if ($ result ->isValid ()) {
76
+ if (!method_exists ($ authenticator , 'getConfig ' )) {
77
+ throw new UnexpectedValueException ('Authenticators must implement method `getConfig` to check when 2fa is required ' );
78
+ }
74
79
$ skipTwoFactorVerify = $ authenticator ->getConfig ('skipTwoFactorVerify ' );
75
80
$ userData = $ result ->getData ();
76
81
if ($ userData instanceof EntityInterface) {
Original file line number Diff line number Diff line change 10
10
use Cake \Core \Configure ;
11
11
use Cake \ORM \TableRegistry ;
12
12
use Psr \Http \Message \ServerRequestInterface ;
13
+ use UnexpectedValueException ;
13
14
14
15
class OneTimeTokenAuthenticator extends AbstractAuthenticator implements AuthenticatorInterface
15
16
{
@@ -29,6 +30,13 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
29
30
}
30
31
31
32
$ usersTable = TableRegistry::getTableLocator ()->get (Configure::read ('Users.table ' ));
33
+ if (!method_exists ($ usersTable , 'loginWithToken ' )) {
34
+ throw new UnexpectedValueException (sprintf (
35
+ '%s requires to implement `%s::loginWithToken` ' ,
36
+ self ::class,
37
+ get_class ($ usersTable )
38
+ ));
39
+ }
32
40
33
41
$ user = $ usersTable ->loginWithToken ($ token );
34
42
Original file line number Diff line number Diff line change @@ -48,11 +48,7 @@ public function __construct(array $config = [])
48
48
}
49
49
50
50
/**
51
- * Check permission
52
- *
53
- * @param \Authorization\IdentityInterface|null $identity user identity
54
- * @param \Psr\Http\Message\ServerRequestInterface $resource server request
55
- * @return bool
51
+ * @inheritDoc
56
52
*/
57
53
public function canAccess (?IdentityInterface $ identity , ServerRequestInterface $ resource ): ResultInterface
58
54
{
You can’t perform that action at this time.
0 commit comments