Skip to content

Commit d04a54c

Browse files
author
Caitlin Bales (MSFT)
authored
Merge pull request #80 from microsoftgraph/revert-79-patch-5
Revert "Be able to change the accessToken of a request"
2 parents e544768 + dd45e3a commit d04a54c

4 files changed

Lines changed: 40 additions & 84 deletions

File tree

src/Http/GraphRequest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,6 @@ public function __construct($requestType, $endpoint, $accessToken, $baseUrl, $ap
133133
$this->proxyPort = $proxyPort;
134134
}
135135

136-
/**
137-
* Sets a new accessToken
138-
*
139-
* @param string $accessToken A valid access token to validate the Graph call
140-
*
141-
* @return GraphRequest object
142-
*/
143-
public function setAccessToken($accessToken)
144-
{
145-
$this->accessToken = $accessToken;
146-
$this->headers['Authorization'] = 'Bearer ' . $this->accessToken;
147-
return $this;
148-
}
149-
150136
/**
151137
* Sets the return type of the response object
152138
*

tests/Functional/DeltaQueryTest.php

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
class DeltaQueryTest extends TestCase
77
{
88
private $_client;
9-
private $graphTestBase;
109

1110
protected function setUp()
1211
{
13-
$this->graphTestBase = new GraphTestBase();
14-
$this->_client = $this->graphTestBase->graphClient;
12+
$graphTestBase = new GraphTestBase();
13+
$this->_client = $graphTestBase->graphClient;
1514
}
1615

1716
/**
@@ -47,29 +46,4 @@ public function testDeltaQuery()
4746
// Count is likely 0 but collection should not be null
4847
$this->assertNotNull($groups);
4948
}
50-
51-
/**
52-
* @group functional
53-
*/
54-
public function testSetAccessToken()
55-
{
56-
$this->_client->setApiVersion("beta");
57-
$deltaPageRequest = $this->_client->createCollectionRequest("GET", "/groups/delta")
58-
->setReturnType(Model\Group::class);
59-
60-
// Test if we can change the accessToken
61-
while (!$deltaPageRequest->isEnd()) {
62-
// Store authentication-header
63-
$oldAuthenticationHeader = $deltaPageRequest->getHeaders()['Authorization'];
64-
// Set a new delta-token
65-
$deltaPageRequest->setAccessToken($this->graphTestBase->getAccessToken());
66-
// Get the new authentication-header
67-
$newAuthenticationHeader = $deltaPageRequest->getHeaders()['Authorization'];
68-
// Do the actual request
69-
$groups = $deltaPageRequest->getPage();
70-
71-
$this->assertNotSame($oldAuthenticationHeader,$newAuthenticationHeader);
72-
$this->assertNotNull($groups);
73-
}
74-
}
75-
}
49+
}

tests/Functional/GraphTestBase.php

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,53 @@
66

77
class GraphTestBase
88
{
9-
private $clientId;
10-
private $clientSecret;
11-
private $username;
12-
private $password;
13-
private $contentType = "application/x-www-form-urlencoded";
14-
private $grantType = "password";
15-
private $endpoint = "https://login.microsoftonline.com/common/oauth2/token";
16-
private $resource = "https%3A%2F%2Fgraph.microsoft.com%2F";
17-
public $graphClient;
9+
private $clientId;
10+
private $username;
11+
private $password;
12+
private $contentType = "application/x-www-form-urlencoded";
13+
private $grantType = "password";
14+
private $endpoint = "https://login.microsoftonline.com/common/oauth2/token";
15+
private $resource = "https%3A%2F%2Fgraph.microsoft.com%2F";
16+
private $accessToken;
17+
public $graphClient;
1818

1919
public function __construct()
2020
{
21-
$this->clientId = CLIENT_ID;
22-
$this->clientSecret = CLIENT_SECRET;
23-
$this->username = USERNAME;
24-
$this->password = PASSWORD;
21+
$this->clientId = CLIENT_ID;
22+
$this->username = USERNAME;
23+
$this->password = PASSWORD;
2524

2625
$this->getAuthenticatedClient();
2726
}
2827

2928
public function getAuthenticatedClient()
3029
{
31-
if ($this->graphClient == null)
32-
{
33-
$this->graphClient = new Graph();
34-
$this->graphClient->setAccessToken($this->getAccessToken());
35-
}
30+
if ($this->graphClient == null)
31+
{
32+
$this->graphClient = new Graph();
33+
$this->graphClient->setAccessToken($this->getAccessToken());
34+
}
3635
}
3736

38-
public function getAccessToken()
37+
private function getAccessToken()
3938
{
40-
$body = "grant_type=".$this->grantType
41-
."&resource=".$this->resource
42-
."&client_id=".$this->clientId
43-
."&client_secret=".$this->clientSecret
44-
."&username=".$this->username
45-
."&password=".$this->password;
46-
$ch = curl_init();
47-
curl_setopt($ch, CURLOPT_URL, $this->endpoint);
48-
curl_setopt($ch, CURLOPT_POST, 1);
49-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
50-
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
51-
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
52-
curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->contentType, 'Content-Length: ' . strlen($body)));
53-
54-
$result = curl_exec ($ch);
55-
$token = json_decode($result, true)['access_token'];
56-
curl_close($ch);
57-
58-
return $token;
39+
$body = "grant_type=".$this->grantType.
40+
"&resource=".$this->resource.
41+
"&client_id=".$this->clientId.
42+
"&username=".$this->username.
43+
"&password=".$this->password;
44+
$ch = curl_init();
45+
curl_setopt($ch, CURLOPT_URL, $this->endpoint);
46+
curl_setopt($ch, CURLOPT_POST, 1);
47+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
48+
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
49+
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
50+
curl_setopt($ch, CURLOPT_HTTPHEADER, array($this->contentType, 'Content-Length: ' . strlen($body)));
51+
52+
$result = curl_exec ($ch);
53+
$token = json_decode($result, true)['access_token'];
54+
curl_close($ch);
55+
56+
return $token;
5957
}
60-
61-
}
58+
}

tests/Functional/TestConstants.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* possible.
1313
*/
1414
define("CLIENT_ID", getenv("client_id"));
15-
define("CLIENT_SECRET", getenv("client_secret"));
1615
define ("USERNAME", getenv("test_username"));
1716
define("PASSWORD", getenv("test_password"));
1817

0 commit comments

Comments
 (0)