1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015 François Kooman <[email protected]>. |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace fkooman\RemoteStorage\OAuth\Storage; |
20
|
|
|
|
21
|
|
|
use fkooman\RemoteStorage\OAuth\ResourceServer; |
22
|
|
|
use fkooman\RemoteStorage\OAuth\ResourceServerStorageInterface; |
23
|
|
|
use RuntimeException; |
24
|
|
|
|
25
|
|
|
class JsonResourceServerStorage implements ResourceServerStorageInterface |
26
|
|
|
{ |
27
|
|
|
/** @var string */ |
28
|
|
|
private $jsonFile; |
29
|
|
|
|
30
|
|
|
public function __construct($jsonFile) |
31
|
|
|
{ |
32
|
|
|
$this->jsonFile = $jsonFile; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getResourceServer($resourceServerId) |
36
|
|
|
{ |
37
|
|
|
if (false === $fileData = @file_get_contents($this->jsonFile)) { |
38
|
|
|
throw new RuntimeException('error reading file'); |
39
|
|
|
} |
40
|
|
|
$data = json_decode($fileData, true); |
41
|
|
|
if (!array_key_exists($resourceServerId, $data)) { |
42
|
|
|
return false; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return new ResourceServer( |
46
|
|
|
$resourceServerId, |
47
|
|
|
$data[$resourceServerId]['scope'], |
48
|
|
|
$data[$resourceServerId]['secret'] |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|