@@ 92-125 (lines=34) @@ | ||
89 | /** |
|
90 | * {@inheritdoc} |
|
91 | */ |
|
92 | public function refreshAccessToken() |
|
93 | { |
|
94 | try { |
|
95 | $response = $this->client->makeCall( |
|
96 | $this->getAuthenticationUrl(), |
|
97 | array(), |
|
98 | array(), |
|
99 | 'POST', |
|
100 | array( |
|
101 | 'client_id' => $this->getClientId(), |
|
102 | 'grant_type' => self::REFRESH_GRANT_TYPE, |
|
103 | 'username' => $this->getUsername(), |
|
104 | 'refresh_token' => $this->refreshToken |
|
105 | ) |
|
106 | ); |
|
107 | } catch (ClientException $e) { |
|
108 | throw new AuthenticationException('Could not refresh access token.', $e->getCode(), $e); |
|
109 | } |
|
110 | ||
111 | try { |
|
112 | $responseObj = ContentApiSdk::getValidJsonObj($response['body']); |
|
113 | } catch (InvalidDataException $e) { |
|
114 | throw new AuthenticationException('Authentication response body is not (valid) json.', $e->getCode(), $e); |
|
115 | } |
|
116 | ||
117 | if (property_exists($responseObj, 'access_token') && property_exists($responseObj, 'refresh_token')) { |
|
118 | $this->accessToken = $responseObj->access_token; |
|
119 | $this->refreshToken = $responseObj->refresh_token; |
|
120 | ||
121 | return true; |
|
122 | } |
|
123 | ||
124 | throw new AuthenticationException('The server returned an unexpected response body.'); |
|
125 | } |
|
126 | ||
127 | /** |
|
128 | * {@inheritdoc} |
|
@@ 130-163 (lines=34) @@ | ||
127 | /** |
|
128 | * {@inheritdoc} |
|
129 | */ |
|
130 | public function getAuthenticationTokens() |
|
131 | { |
|
132 | try { |
|
133 | $response = $this->client->makeCall( |
|
134 | $this->getAuthenticationUrl(), |
|
135 | array(), |
|
136 | array(), |
|
137 | 'POST', |
|
138 | array( |
|
139 | 'client_id' => $this->getClientId(), |
|
140 | 'grant_type' => self::AUTHENTICATION_GRANT_TYPE, |
|
141 | 'username' => $this->getUsername(), |
|
142 | 'password' => $this->getPassword() |
|
143 | ) |
|
144 | ); |
|
145 | } catch (ClientException $e) { |
|
146 | throw new AuthenticationException('Could not request access token.', $e->getCode(), $e); |
|
147 | } |
|
148 | ||
149 | try { |
|
150 | $responseObj = ContentApiSdk::getValidJsonObj($response['body']); |
|
151 | } catch (InvalidDataException $e) { |
|
152 | throw new AuthenticationException('Authentication response body is not (valid) json.', $e->getCode(), $e); |
|
153 | } |
|
154 | ||
155 | if (property_exists($responseObj, 'access_token') && property_exists($responseObj, 'refresh_token')) { |
|
156 | $this->accessToken = $responseObj->access_token; |
|
157 | $this->refreshToken = $responseObj->refresh_token; |
|
158 | ||
159 | return true; |
|
160 | } |
|
161 | ||
162 | throw new AuthenticationException('The server returned an unexpected response body.'); |
|
163 | } |
|
164 | } |
|
165 |