Skip to content

Commit 97a5f4a

Browse files
author
Georgiy
authored
Merge pull request #565 from Lusitanian/pull/552
Pull/552
2 parents 1cefdb5 + 6b517c4 commit 97a5f4a

6 files changed

Lines changed: 237 additions & 339 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ Included service implementations
4444
- Scoop.it!
4545
- Tumblr
4646
- Twitter
47-
- Xing
4847
- Yahoo
4948
- OAuth2
5049
- Amazon
@@ -86,6 +85,7 @@ Included service implementations
8685
- Ustream
8786
- Vimeo
8887
- Vkontakte
88+
- Xing
8989
- Yahoo
9090
- Yammer
9191
- more to come!

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"scripts" : {
2121
"tests" : [
22-
"./vendor/bin/phpunit"
22+
"./vendor/bin/phpunit --color=always"
2323
],
2424
"check" : [
2525
"./vendor/bin/php-cs-fixer fix --ansi --dry-run --diff",

src/OAuth/OAuth1/Service/Xing.php

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/OAuth/OAuth2/Service/Xing.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace OAuth\OAuth2\Service;
4+
5+
use OAuth\Common\Consumer\CredentialsInterface;
6+
use OAuth\Common\Http\Client\ClientInterface;
7+
use OAuth\Common\Http\Exception\TokenResponseException;
8+
use OAuth\Common\Http\Uri\Uri;
9+
use OAuth\Common\Http\Uri\UriInterface;
10+
use OAuth\Common\Storage\TokenStorageInterface;
11+
use OAuth\OAuth2\Token\StdOAuth2Token;
12+
13+
/**
14+
* @see https://dev.xing.com/docs/authentication
15+
*/
16+
class Xing extends AbstractService
17+
{
18+
public function __construct(
19+
CredentialsInterface $credentials,
20+
ClientInterface $httpClient,
21+
TokenStorageInterface $storage,
22+
$scopes = [],
23+
?UriInterface $baseApiUri = null,
24+
$stateParameterInAutUrl = false,
25+
$apiVersion = ''
26+
) {
27+
parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, $stateParameterInAutUrl, $apiVersion);
28+
29+
if (null === $baseApiUri) {
30+
$this->baseApiUri = new Uri('https://api.xing.com/v1/');
31+
}
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function getAuthorizationEndpoint()
38+
{
39+
return new Uri('https://api.xing.com/auth/oauth2/authorize');
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function getAccessTokenEndpoint()
46+
{
47+
return new Uri('https://api.xing.com/auth/oauth2/token');
48+
}
49+
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
protected function getAuthorizationMethod()
54+
{
55+
return static::AUTHORIZATION_METHOD_HEADER_BEARER;
56+
}
57+
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
protected function parseAccessTokenResponse($responseBody)
62+
{
63+
$data = json_decode($responseBody, true);
64+
65+
if (null === $data || !is_array($data)) {
66+
throw new TokenResponseException('Unable to parse response.');
67+
} elseif (isset($data['error'])) {
68+
throw new TokenResponseException(sprintf(
69+
'Error in retrieving access token, error: "%s", description: "%s", uri: "%s".',
70+
$data['error'],
71+
$data['error_description'],
72+
$data['error_uri']
73+
)
74+
);
75+
}
76+
77+
$token = new StdOAuth2Token();
78+
$token->setAccessToken($data['access_token']);
79+
$token->setLifeTime($data['expires_in']);
80+
$token->setRefreshToken($data['refresh_token']);
81+
82+
unset($data['access_token'], $data['expires_in'], $data['refresh_token']);
83+
84+
$token->setExtraParams($data);
85+
86+
return $token;
87+
}
88+
}

0 commit comments

Comments
 (0)