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\Client; |
22
|
|
|
use fkooman\RemoteStorage\OAuth\ClientStorageInterface; |
23
|
|
|
|
24
|
|
|
class ArrayClientStorage implements ClientStorageInterface |
25
|
|
|
{ |
26
|
|
|
/** @var array */ |
27
|
|
|
private $clientConfig; |
28
|
|
|
|
29
|
|
|
public function __construct(array $clientConfig) |
30
|
|
|
{ |
31
|
|
|
$this->clientConfig = $clientConfig; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getClient($clientId, $responseType = null, $redirectUri = null, $scope = null) |
35
|
|
|
{ |
36
|
|
|
if (!array_key_exists($clientId, $this->clientConfig)) { |
37
|
|
|
return false; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
// secret is not always needed |
41
|
|
|
$clientSecret = array_key_exists('secret', $this->clientConfig[$clientId]) ? $this->clientConfig[$clientId]['secret'] : null; |
42
|
|
|
|
43
|
|
|
return new Client( |
44
|
|
|
$clientId, |
45
|
|
|
$this->clientConfig[$clientId]['response_type'], |
46
|
|
|
$this->clientConfig[$clientId]['redirect_uri'], |
47
|
|
|
$this->clientConfig[$clientId]['scope'], |
48
|
|
|
$clientSecret |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|