Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the microsoft graph service is added #544

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Included service implementations
- LinkedIn
- Mailchimp
- Microsoft
- Microsoft Graph
- Mondo
- Nest
- Netatmo
Expand Down
79 changes: 65 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

/**
* Create a new instance of the URI class with the current URI, stripping the query string
*/

$uriFactory = new \OAuth\Common\Http\Uri\UriFactory();
$currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
$currentUri->setQuery('');
$currentUri->setQuery('');*/

/**
* Load the credential for the different services
Expand Down
5 changes: 5 additions & 0 deletions examples/init.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@
'key' => '',
'secret' => ''
),
'microsoft_grapht' => array(
'CLIENT_ID' => '',
'SECRET_CLIENT' => '',
'CALLBACK_URL' => ''
)
);

/** @var $serviceFactory \OAuth\ServiceFactory An OAuth service factory. */
Expand Down
38 changes: 38 additions & 0 deletions examples/microsoftGraph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use OAuth\Common\Consumer\Credentials;
use OAuth\Common\Http\Client\CurlClient;
use OAuth\Common\Storage\Session;

require_once __DIR__ . '/bootstrap.php';


$storage = new Session();

$credentials = new Credentials(
$servicesCredentials['microsoftgraph']['CLIENT_ID'],
$servicesCredentials['microsoftgraph']['SECRET_CLIENT'],
$servicesCredentials['microsoftgraph']['CALLBACK_URL']
);

//Se le asigna el cliente para hacer las peticiones
$serviceFactory->setHttpClient(new CurlClient);
$microsofttGraphtnService = $serviceFactory->createService('microsoftgraph', $credentials, $storage);


if (!empty($_GET['code'])) {
// Obtiene el token a partir del codigo que se obtiene del callback
$token = $microsofttGraphtnService->requestAccessToken($_GET['code']);

// Send a request para obtener las licencias que tiene el tenant
$result = json_decode($microsofttGraphtnService->request('/subscribedSkus?api-version=1.6'), true);

// Se muestra el resultado
echo "<pre>";
var_dump($result);
echo "</pre>";

} else {
$url = $microsofttGraphtnService->getAuthorizationUri();
header('Location: ' . $url);
}
45 changes: 45 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="true"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
testSuiteLoaderFile="./vendor/phpunit/phpunit/PHPUnit/Runner/StandardTestSuiteLoader.php"
strict="false"
verbose="false">
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
<exclude>
<file>src/OAuth/bootstrap.php</file>
<file>src/OAuth/Common/Exception/Exception.php</file>
<file>src/OAuth/Common/Http/Exception/TokenResponseException.php</file>
<file>src/OAuth/Common/Storage/Exception/StorageException.php</file>
<file>src/OAuth/Common/Storage/Exception/TokenNotFoundException.php</file>
<file>src/OAuth/Common/Token/Exception/ExpiredTokenException.php</file>
<file>src/OAuth/OAuth1/Signature/Exception/UnsupportedHashAlgorithmException.php</file>
<file>src/OAuth/OAuth2/Service/Exception/InvalidScopeException.php</file>
<file>src/OAuth/OAuth2/Service/Exception/MissingRefreshTokenException.php</file>
<file>src/OAuth/OAuth2/Token/StdOAuth2Token.php</file>
</exclude>
</whitelist>
</filter>
<php>
<env name="redis_host" value="127.0.0.1"/>
<env name="redis_port" value="6379"/>
</php>
</phpunit>
7 changes: 3 additions & 4 deletions src/OAuth/Common/Http/Client/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public function retrieveResponse(

curl_setopt($ch, CURLOPT_URL, $endpoint->getAbsoluteUri());

if ($method === 'POST' || $method === 'PUT') {
if ($method === 'POST' || $method === 'PUT' || $method === 'PATCH') {
if ($requestBody && is_array($requestBody)) {
$requestBody = http_build_query($requestBody, '', '&');
}

if ($method === 'PUT') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
if ($method === 'PUT' || $method === 'PATCH') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
} else {
curl_setopt($ch, CURLOPT_POST, true);
}
Expand All @@ -102,7 +102,6 @@ public function retrieveResponse(
} else {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
}

if ($this->maxRedirects > 0) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->maxRedirects);
Expand Down
Loading