Skip to content

Commit 9d7d872

Browse files
committed
Introduce browser session and token bearer interfaces
1 parent 265e077 commit 9d7d872

File tree

4 files changed

+48
-53
lines changed

4 files changed

+48
-53
lines changed

src/Adapter/BrowserSessionAdapter.php

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* (c) A51 doo <[email protected]>. All rights reserved.
77
*/
88

9+
declare(strict_types=1);
10+
911
namespace ActiveCollab\Authentication\Adapter;
1012

1113
use ActiveCollab\Authentication\AuthenticatedUser\AuthenticatedUserInterface;
@@ -27,38 +29,19 @@
2729
use Psr\Http\Message\ResponseInterface;
2830
use Psr\Http\Message\ServerRequestInterface;
2931

30-
/**
31-
* @package ActiveCollab\Authentication\Adapter
32-
*/
33-
class BrowserSessionAdapter extends Adapter
32+
class BrowserSessionAdapter extends Adapter implements BrowserSessionAdapterInterface
3433
{
35-
/**
36-
* @var UserRepositoryInterface
37-
*/
3834
private $user_repository;
39-
40-
/**
41-
* @var SessionRepositoryInterface
42-
*/
4335
private $session_repository;
44-
45-
/**
46-
* @var CookiesInterface
47-
*/
4836
private $cookies;
49-
50-
/**
51-
* @var string
52-
*/
5337
private $session_cookie_name;
5438

55-
/**
56-
* @param UserRepositoryInterface $user_repository
57-
* @param SessionRepositoryInterface $session_repository
58-
* @param CookiesInterface $cookies
59-
* @param string $session_cookie_name
60-
*/
61-
public function __construct(UserRepositoryInterface $user_repository, SessionRepositoryInterface $session_repository, CookiesInterface $cookies, $session_cookie_name = 'sessid')
39+
public function __construct(
40+
UserRepositoryInterface $user_repository,
41+
SessionRepositoryInterface $session_repository,
42+
CookiesInterface $cookies,
43+
string $session_cookie_name = 'sessid'
44+
)
6245
{
6346
if (empty($session_cookie_name)) {
6447
throw new InvalidArgumentException('Session cookie name is required');
@@ -70,9 +53,6 @@ public function __construct(UserRepositoryInterface $user_repository, SessionRep
7053
$this->session_cookie_name = $session_cookie_name;
7154
}
7255

73-
/**
74-
* {@inheritdoc}
75-
*/
7656
public function initialize(ServerRequestInterface $request)
7757
{
7858
$session_id = $this->cookies->get($request, $this->session_cookie_name);
@@ -148,17 +128,11 @@ public function applyToResponse(ResponseInterface $response, TransportInterface
148128
return $response;
149129
}
150130

151-
/**
152-
* {@inheritdoc}
153-
*/
154131
public function authenticate(AuthenticatedUserInterface $authenticated_user, array $credentials = [])
155132
{
156133
return $this->session_repository->createSession($authenticated_user, $credentials);
157134
}
158135

159-
/**
160-
* {@inheritdoc}
161-
*/
162136
public function terminate(AuthenticationResultInterface $authenticated_with)
163137
{
164138
if (!$authenticated_with instanceof SessionInterface) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ActiveCollab\Authentication\Adapter;
6+
7+
use ActiveCollab\Authentication\AuthenticatedUser\AuthenticatedUserInterface;
8+
use ActiveCollab\Authentication\AuthenticationResult\AuthenticationResultInterface;
9+
use ActiveCollab\Authentication\AuthenticationResult\Transport\TransportInterface;
10+
use Psr\Http\Message\ResponseInterface;
11+
use Psr\Http\Message\ServerRequestInterface;
12+
13+
interface BrowserSessionAdapterInterface extends AdapterInterface
14+
{
15+
}

src/Adapter/TokenBearerAdapter.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* (c) A51 doo <[email protected]>. All rights reserved.
77
*/
88

9+
declare(strict_types=1);
10+
911
namespace ActiveCollab\Authentication\Adapter;
1012

1113
use ActiveCollab\Authentication\AuthenticatedUser\AuthenticatedUserInterface;
@@ -19,26 +21,15 @@
1921
use InvalidArgumentException;
2022
use Psr\Http\Message\ServerRequestInterface;
2123

22-
/**
23-
* @package ActiveCollab\Authentication\Adapter
24-
*/
25-
class TokenBearerAdapter extends Adapter
24+
class TokenBearerAdapter extends Adapter implements TokenBearerAdapterInterface
2625
{
27-
/**
28-
* @var UserRepositoryInterface
29-
*/
3026
private $user_repository;
31-
32-
/**
33-
* @var TokenRepositoryInterface
34-
*/
3527
private $token_repository;
3628

37-
/**
38-
* @param UserRepositoryInterface $user_repository
39-
* @param TokenRepositoryInterface $token_repository
40-
*/
41-
public function __construct(UserRepositoryInterface $user_repository, TokenRepositoryInterface $token_repository)
29+
public function __construct(
30+
UserRepositoryInterface $user_repository,
31+
TokenRepositoryInterface $token_repository
32+
)
4233
{
4334
$this->user_repository = $user_repository;
4435
$this->token_repository = $token_repository;
@@ -55,11 +46,11 @@ public function initialize(ServerRequestInterface $request)
5546

5647
$authorization = $request->getHeaderLine('Authorization');
5748

58-
if (empty($authorization) || substr($authorization, 0, 6) !== 'Bearer') {
49+
if (empty($authorization) || mb_substr($authorization, 0, 6) !== 'Bearer') {
5950
return null;
6051
}
6152

62-
$token_id = trim(substr($authorization, 7));
53+
$token_id = trim(mb_substr($authorization, 7));
6354

6455
if ($token_id === null || $token_id === '') {
6556
throw new InvalidTokenException();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Active Collab Authentication project.
5+
*
6+
* (c) A51 doo <[email protected]>. All rights reserved.
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace ActiveCollab\Authentication\Adapter;
12+
13+
interface TokenBearerAdapterInterface extends AdapterInterface
14+
{
15+
}

0 commit comments

Comments
 (0)