Skip to content

Commit a72bb11

Browse files
committed
Initial commit
0 parents  commit a72bb11

25 files changed

+666
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/
2+
composer.lock

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "micro/plugin-security",
3+
"description": "Micro Framework: Security component",
4+
"type": "library",
5+
"license": "MIT",
6+
"version": "0.1",
7+
"autoload": {
8+
"psr-4": {
9+
"Micro\\Plugin\\Security\\": "src/"
10+
}
11+
},
12+
"authors": [
13+
{
14+
"name": "Stanislau Komar",
15+
"email": "stanislau_komar@epam.com"
16+
}
17+
],
18+
"require": {
19+
"firebase/php-jwt": "^6"
20+
}
21+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Micro\Plugin\Security\Business\Provider;
4+
5+
use Micro\Plugin\Security\Business\Token\Context\TokenConfiguration;
6+
use Micro\Plugin\Security\Configuration\Provider\ProviderConfigurationInterface;
7+
use Micro\Plugin\Security\Token\TokenInterface;
8+
9+
class SecurityProvider implements SecurityProviderInterface
10+
{
11+
/**
12+
* @param ProviderConfigurationInterface $providerConfiguration
13+
*/
14+
public function __construct(
15+
private readonly ProviderConfigurationInterface $providerConfiguration
16+
)
17+
{
18+
}
19+
20+
public function generateToken(TokenConfiguration $tokenConfiguration): TokenInterface
21+
{
22+
// TODO: Implement generateToken() method.
23+
}
24+
25+
public function decodeToken(string $encoded): TokenInterface
26+
{
27+
// TODO: Implement decodeToken() method.
28+
}
29+
30+
/**
31+
* @return string
32+
*/
33+
public function getName(): string
34+
{
35+
return $this->getName();
36+
}
37+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Micro\Plugin\Security\Business\Provider;
4+
5+
6+
interface SecurityProviderInterface
7+
{
8+
/**
9+
* @return string
10+
*/
11+
public function getName(): string;
12+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Micro\Plugin\Security\Business\Token\Context;
4+
5+
class TokenConfiguration
6+
{
7+
/**
8+
* @var int
9+
*/
10+
private int $createdAt;
11+
12+
/**
13+
* @param array $parameters
14+
* @param int $lifetime
15+
*/
16+
public function __construct(
17+
private readonly array $parameters,
18+
private int $lifetime = 0
19+
)
20+
{
21+
$this->createdAt = time();
22+
}
23+
24+
/**
25+
* @return int
26+
*/
27+
public function getCreatedAt(): int
28+
{
29+
return $this->createdAt;
30+
}
31+
32+
/**
33+
* @return int
34+
*/
35+
public function getLifetime(): int
36+
{
37+
return $this->lifetime;
38+
}
39+
40+
/**
41+
* @return array
42+
*/
43+
public function getParameters(): array
44+
{
45+
return $this->parameters;
46+
}
47+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Micro\Plugin\Security\Business\Token\Decoder;
4+
5+
interface DecoderFactoryInterface
6+
{
7+
/**
8+
* @return DecoderInterface
9+
*/
10+
public function create(): DecoderInterface;
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Micro\Plugin\Security\Business\Token\Decoder;
4+
5+
use Micro\Plugin\Security\Token\TokenInterface;
6+
7+
interface DecoderInterface
8+
{
9+
/**
10+
* @param string $encodedToken
11+
*
12+
* @return array
13+
*/
14+
public function decode(string $encodedToken): array;
15+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Micro\Plugin\Security\Business\Token\Decoder;
4+
5+
use Firebase\JWT\JWT;
6+
use Firebase\JWT\Key;
7+
8+
class JWTDecoder implements DecoderInterface
9+
{
10+
/**
11+
* @param string $publicKey
12+
* @param string $encryptAlgorithm
13+
*/
14+
public function __construct(
15+
private readonly string $publicKey,
16+
private readonly string $encryptAlgorithm
17+
)
18+
{
19+
}
20+
21+
/**
22+
* {@inheritDoc}
23+
*/
24+
public function decode(string $encodedToken): array
25+
{
26+
return (array) JWT::decode($encodedToken, new Key($this->publicKey, $this->encryptAlgorithm));
27+
}
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Micro\Plugin\Security\Business\Token\Decoder;
4+
5+
class JWTDecoderFactory implements DecoderFactoryInterface
6+
{
7+
/**
8+
* {@inheritDoc}
9+
*/
10+
public function create(): DecoderInterface
11+
{
12+
return new JWTDecoder();
13+
}
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Micro\Plugin\Security\Token\Encoder;
4+
5+
interface EncoderFactoryInterface
6+
{
7+
/**
8+
* @return EncoderInterface
9+
*/
10+
public function create(): EncoderInterface;
11+
}

0 commit comments

Comments
 (0)