1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the PHP SDK library for the Superdesk Content API. |
5
|
|
|
* |
6
|
|
|
* Copyright 2015 Sourcefabric z.u. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2015 Sourcefabric z.ú. |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Superdesk\ContentApiSdk\API\Authentication; |
16
|
|
|
|
17
|
|
|
use Superdesk\ContentApiSdk\Client\ClientInterface; |
18
|
|
|
|
19
|
|
|
abstract class AbstractAuthentication implements AuthenticationInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* URI for requesting and refreshing tokens. |
23
|
|
|
*/ |
24
|
|
|
const AUTHENTICATION_URI = 'oauth/token'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* HTTP Client for making authentication requests. |
28
|
|
|
* |
29
|
|
|
* @var ClientInterface |
30
|
|
|
*/ |
31
|
|
|
protected $client; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Access token for the API. |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $accessToken; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Client ID for the API. |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $clientId; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Base url for the api. |
49
|
|
|
* |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
protected $baseUrl; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function __construct(ClientInterface $client) |
58
|
|
|
{ |
59
|
|
|
$this->client = $client; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function getAccessToken() |
66
|
|
|
{ |
67
|
|
|
return $this->accessToken; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Gets the value of clientId. |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function getClientId() |
76
|
|
|
{ |
77
|
|
|
return $this->clientId; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Sets the value of clientId. |
82
|
|
|
* |
83
|
|
|
* @param string $clientId Value to set |
84
|
|
|
* |
85
|
|
|
* @return self |
86
|
|
|
*/ |
87
|
|
|
public function setClientId($clientId) |
88
|
|
|
{ |
89
|
|
|
$this->clientId = $clientId; |
90
|
|
|
|
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Gets the value of baseUrl. |
96
|
|
|
* |
97
|
|
|
* @return mixed |
98
|
|
|
*/ |
99
|
|
|
public function getBaseUrl() |
100
|
|
|
{ |
101
|
|
|
return $this->baseUrl; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Sets the value of baseUrl. |
106
|
|
|
* |
107
|
|
|
* @param mixed $baseUrl Value to set |
108
|
|
|
* |
109
|
|
|
* @return self |
110
|
|
|
*/ |
111
|
|
|
public function setBaseUrl($baseUrl) |
112
|
|
|
{ |
113
|
|
|
$this->baseUrl = $baseUrl; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns the url where authentication tokens can be retrieved. |
120
|
|
|
* |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
public function getAuthenticationUrl() |
124
|
|
|
{ |
125
|
|
|
return sprintf('%s/%s', rtrim($this->getBaseUrl(), '/ '), self::AUTHENTICATION_URI); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|