1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the tiqr project. |
4
|
|
|
* |
5
|
|
|
* The tiqr project aims to provide an open implementation for |
6
|
|
|
* authentication using mobile devices. It was initiated by |
7
|
|
|
* SURFnet and developed by Egeniq. |
8
|
|
|
* |
9
|
|
|
* More information: http://www.tiqr.org |
10
|
|
|
* |
11
|
|
|
* @author Lineke Kerckhoffs-Willems <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @package tiqr |
14
|
|
|
* |
15
|
|
|
* @license New BSD License - See LICENSE file for details. |
16
|
|
|
* |
17
|
|
|
* @copyright (C) 2014 SURFnet BV |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
use Psr\Log\LoggerInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* OATHService storage for user's secret |
24
|
|
|
*/ |
25
|
|
|
class Tiqr_UserSecretStorage_OathServiceClient implements Tiqr_UserSecretStorage_Interface |
26
|
|
|
{ |
27
|
|
|
private $client; |
28
|
|
|
/** |
29
|
|
|
* @var LoggerInterface |
30
|
|
|
*/ |
31
|
|
|
private LoggerInterface $logger; |
32
|
|
|
|
33
|
3 |
|
public function __construct(Tiqr_API_Client $client, LoggerInterface $logger) |
34
|
|
|
{ |
35
|
3 |
|
$this->logger = $logger; |
36
|
3 |
|
$this->client = $client; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get the user's secret |
41
|
|
|
* Not implemented because the idea of the oathservice is that secrets cannot be retrieved |
42
|
|
|
* |
43
|
|
|
* @param String $userId |
44
|
|
|
* |
45
|
|
|
* @return string The user's secret |
46
|
|
|
* @throws Exception |
47
|
|
|
*/ |
48
|
1 |
|
public function getSecret(string $userId): string |
49
|
|
|
{ |
50
|
|
|
// By design the keyserver calculates the OCRA response but never revels the secret |
51
|
1 |
|
$this->logger->error('Calling getUserSecret on the OathServiceClient is not supported'); |
52
|
1 |
|
throw new RuntimeException('Calling getUserSecret on the OathServiceClient is not supported'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Store a secret for a user |
57
|
|
|
* |
58
|
|
|
* Note that this storage engine does not use the encryption mechnism that PDO and File storage do implement. This |
59
|
|
|
* is taken care of by the OathService itself. |
60
|
|
|
* |
61
|
|
|
* @param string $userId |
62
|
|
|
* @param string $secret |
63
|
|
|
* @throws Exception |
64
|
|
|
*/ |
65
|
1 |
|
public function setSecret(string $userId, string $secret): void |
66
|
|
|
{ |
67
|
1 |
|
$this->logger->info('Storing the user secret on the OathServiceClient (api call)'); |
68
|
1 |
|
$this->client->call('/secrets/'.urlencode($userId), 'POST', array('secret' => $secret)); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|