Skip to content

Commit f24f79d

Browse files
committed
Remove support for image urls
1 parent 7599a68 commit f24f79d

File tree

4 files changed

+21
-120
lines changed

4 files changed

+21
-120
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
# Changelog
22
All Notable changes to `oauth2-microsoft` will be documented in this file
33

4+
## 2.2.0 - 2017-06-07
5+
6+
### Added
7+
- Nothing
8+
9+
### Deprecated
10+
- Nothing
11+
12+
### Fixed
13+
- Nothing
14+
15+
### Removed
16+
- Support for retrieving image urls.
17+
18+
### Security
19+
- Nothing
20+
421
## 2.1.0 - 2017-06-04
522

623
### Added

src/Provider/Microsoft.php

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ protected function checkResponse(ResponseInterface $response, $data)
9393
*/
9494
protected function createResourceOwner(array $response, AccessToken $token)
9595
{
96-
$user = new MicrosoftResourceOwner($response);
97-
98-
$imageUrl = $this->getUserImageUrl($response, $token);
99-
100-
return $user->setImageurl($imageUrl);
96+
return new MicrosoftResourceOwner($response);
10197
}
10298

10399
/**
@@ -113,42 +109,4 @@ public function getResourceOwnerDetailsUrl(AccessToken $token)
113109

114110
return (string) Uri::withQueryValue($uri, 'access_token', (string) $token);
115111
}
116-
117-
/**
118-
* Get user image from provider
119-
*
120-
* @param array $response
121-
* @param AccessToken $token
122-
*
123-
* @return array
124-
*/
125-
protected function getUserImage(array $response, AccessToken $token)
126-
{
127-
$url = 'https://apis.live.net/v5.0/'.$response['id'].'/picture';
128-
129-
$request = $this->getAuthenticatedRequest('get', $url, $token);
130-
131-
$response = $this->getResponse($request);
132-
133-
return json_decode((string) $response->getBody(), true);
134-
}
135-
136-
/**
137-
* Get user image url from provider, if available
138-
*
139-
* @param array $response
140-
* @param AccessToken $token
141-
*
142-
* @return string
143-
*/
144-
protected function getUserImageUrl(array $response, AccessToken $token)
145-
{
146-
$image = $this->getUserImage($response, $token);
147-
148-
if (isset($image['url'])) {
149-
return $image['url'];
150-
}
151-
152-
return null;
153-
}
154112
}

src/Provider/MicrosoftResourceOwner.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ public function __construct(array $response = array())
2121
$this->response = $response;
2222
}
2323

24-
/**
25-
* Image url
26-
*
27-
* @var string
28-
*/
29-
protected $imageurl;
30-
3124
/**
3225
* Get user id
3326
*
@@ -58,28 +51,6 @@ public function getFirstname()
5851
return $this->response['first_name'] ?: null;
5952
}
6053

61-
/**
62-
* Get user imageurl
63-
*
64-
* @return string|null
65-
*/
66-
public function getImageurl()
67-
{
68-
return $this->imageurl;
69-
}
70-
71-
/**
72-
* Set user imageurl
73-
*
74-
* @return string|null
75-
*/
76-
public function setImageurl($imageurl)
77-
{
78-
$this->imageurl = $imageurl;
79-
80-
return $this;
81-
}
82-
8354
/**
8455
* Get user lastname
8556
*

tests/src/Provider/MicrosoftTest.php

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function testGetAccessToken()
111111
$this->assertNull($token->getResourceOwnerId());
112112
}
113113

114-
public function testUserDataWithoutImage()
114+
public function testUserData()
115115
{
116116
$email = uniqid();
117117
$firstname = uniqid();
@@ -128,14 +128,10 @@ public function testUserDataWithoutImage()
128128
$userResponse->shouldReceive('getBody')->andReturn('{"id": '.$userId.', "name": "'.$name.'", "first_name": "'.$firstname.'", "last_name": "'.$lastname.'", "emails": {"preferred": "'.$email.'"}, "link": "'.$urls.'"}');
129129
$userResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
130130

131-
$imageResponse = m::mock('Psr\Http\Message\ResponseInterface');
132-
$imageResponse->shouldReceive('getBody')->andReturn('{}');
133-
$imageResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
134-
135131
$client = m::mock('GuzzleHttp\ClientInterface');
136132
$client->shouldReceive('send')
137-
->times(3)
138-
->andReturn($postResponse, $userResponse, $imageResponse);
133+
->times(2)
134+
->andReturn($postResponse, $userResponse);
139135
$this->provider->setHttpClient($client);
140136

141137
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
@@ -153,47 +149,6 @@ public function testUserDataWithoutImage()
153149
$this->assertEquals($userId, $user->toArray()['id']);
154150
$this->assertEquals($urls.'/cid-'.$userId, $user->getUrls());
155151
$this->assertEquals($urls.'/cid-'.$userId, $user->toArray()['link'].'/cid-'.$user->toArray()['id']);
156-
$this->assertNull($user->getImageurl());
157-
}
158-
159-
public function testUserDataWithImage()
160-
{
161-
$email = uniqid();
162-
$firstname = uniqid();
163-
$imageurl = uniqid();
164-
$lastname = uniqid();
165-
$name = uniqid();
166-
$userId = rand(1000,9999);
167-
$urls = uniqid();
168-
169-
$postResponse = m::mock('Psr\Http\Message\ResponseInterface');
170-
$postResponse->shouldReceive('getBody')->andReturn('{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": '.$userId.'}');
171-
$postResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
172-
173-
$userResponse = m::mock('Psr\Http\Message\ResponseInterface');
174-
$userResponse->shouldReceive('getBody')->andReturn('{"id": '.$userId.', "name": "'.$name.'", "first_name": "'.$firstname.'", "last_name": "'.$lastname.'", "emails": {"preferred": "'.$email.'"}, "link": "'.$urls.'"}');
175-
$userResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
176-
177-
$imageResponse = m::mock('Psr\Http\Message\ResponseInterface');
178-
$imageResponse->shouldReceive('getBody')->andReturn('{"url":"'.$imageurl.'"}');
179-
$imageResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'json']);
180-
181-
$client = m::mock('GuzzleHttp\ClientInterface');
182-
$client->shouldReceive('send')
183-
->times(3)
184-
->andReturn($postResponse, $userResponse, $imageResponse);
185-
$this->provider->setHttpClient($client);
186-
187-
$token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
188-
$user = $this->provider->getResourceOwner($token);
189-
190-
$this->assertEquals($email, $user->getEmail());
191-
$this->assertEquals($firstname, $user->getFirstname());
192-
$this->assertEquals($imageurl, $user->getImageurl());
193-
$this->assertEquals($lastname, $user->getLastname());
194-
$this->assertEquals($name, $user->getName());
195-
$this->assertEquals($userId, $user->getId());
196-
$this->assertEquals($urls.'/cid-'.$userId, $user->getUrls());
197152
}
198153

199154
/**

0 commit comments

Comments
 (0)