-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathUserEntity.php
More file actions
118 lines (97 loc) · 2.72 KB
/
UserEntity.php
File metadata and controls
118 lines (97 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/*
* This file is part of the simplesamlphp-module-oidc.
*
* Copyright (C) 2018 by the Spanish Research and Academic Network.
*
* This code was developed by Universidad de Córdoba (UCO https://www.uco.es)
* for the RedIRIS SIR service (SIR: http://www.rediris.es/sir)
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SimpleSAML\Module\oidc\Entity;
use League\OAuth2\Server\Entities\UserEntityInterface;
use OpenIDConnectServer\Entities\ClaimSetInterface;
use SimpleSAML\Module\oidc\Entity\Interfaces\MementoInterface;
use SimpleSAML\Module\oidc\Utils\TimestampGenerator;
class UserEntity implements UserEntityInterface, MementoInterface, ClaimSetInterface
{
/**
* @var string
*/
private $identifier;
/**
* @var array
*/
private $claims;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var \DateTime
*/
private $updatedAt;
/**
* Constructor.
*/
private function __construct()
{
}
public static function fromData(string $identifier, array $claims = []): self
{
$user = new self();
$user->identifier = $identifier;
$user->createdAt = TimestampGenerator::utc();
$user->updatedAt = $user->createdAt;
$user->claims = $claims;
return $user;
}
/**
* {@inheritdoc}
*/
public static function fromState(array $state): self
{
$user = new self();
$user->identifier = $state['id'];
$user->claims = json_decode($state['claims'], true, 512, JSON_INVALID_UTF8_SUBSTITUTE);
$user->updatedAt = TimestampGenerator::utc($state['updated_at']);
$user->createdAt = TimestampGenerator::utc($state['created_at']);
return $user;
}
/**
* {@inheritdoc}
*/
public function getState(): array
{
return [
'id' => $this->getIdentifier(),
'claims' => json_encode($this->getClaims(), JSON_INVALID_UTF8_SUBSTITUTE),
'updated_at' => $this->getUpdatedAt()->format('Y-m-d H:i:s'),
'created_at' => $this->getCreatedAt()->format('Y-m-d H:i:s'),
];
}
public function getIdentifier(): string
{
return $this->identifier;
}
public function getClaims(): array
{
return $this->claims;
}
public function setClaims(array $claims): self
{
$this->claims = $claims;
$this->updatedAt = TimestampGenerator::utc();
return $this;
}
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
}