Skip to content

Commit

Permalink
Merge pull request #10 from lukasNo1/master
Browse files Browse the repository at this point in the history
Update the client for the new bexio API platform
  • Loading branch information
christianruhstaller authored Nov 2, 2020
2 parents c166826 + 03ab082 commit 07f6abf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ Get access token
```php
require_once '../vendor/autoload.php';

$clientId = '9999999999999.apps.bexio.com'; // The client id you have received from the bexio support
$clientSecret = 'W1diwrEvHlgQMPRYdr3t6I1z5sQ='; // The client secret you have received from the bexio support
$clientId = 'CLIENT_ID'; // The client id of your app
$clientSecret = 'CLIENT_SECRET'; // The client secret of your app
$redirectUri = 'http://localhost/bexio-api-php-client.php'; // Set here your Url where this script gets called
$scope = 'general'; // A whitespace-separated list of scopes (see https://docs.bexio.com/oauth/scopes/).
$scope = 'openid offline_access'; // A whitespace-separated list of scopes (see https://docs.bexio.com/#section/Authentication/API-Scopes).
$state = '8OTs2JTDcWDaPqV7o9aHVWqM'; // A random sequence. Should be used as a protection against CSRF-Attacks
$credentialsPath = 'client_credentials.json'; // Set the path where the credentials file will be stored

$curl = new \Curl\Curl();

$client = new \Bexio\Client(
[
'clientId' => $clientId,
Expand All @@ -46,8 +44,8 @@ $client->setRedirectUri($redirectUri);
if (!isset($_GET['code'])) {
$redirectTo = \Bexio\Client::OAUTH2_AUTH_URL.'?'.http_build_query(
[
'response_type' => 'code',
'client_id' => $clientId,
'client_secret' => $clientSecret,
'redirect_uri' => $redirectUri,
'scope' => $scope,
'state' => $state,
Expand Down
25 changes: 10 additions & 15 deletions src/Bexio/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

class Client
{
const API_URL = 'https://office.bexio.com/api2.php';
const OAUTH2_AUTH_URL = 'https://office.bexio.com/oauth/authorize';
const OAUTH2_TOKEN_URI = 'https://office.bexio.com/oauth/access_token';
const OAUTH2_REFRESH_TOKEN_URI = 'https://office.bexio.com/oauth/refresh_token';
const API_URL = 'https://api.bexio.com/2.0';
const OAUTH2_AUTH_URL = 'https://idp.bexio.com/authorize';
const OAUTH2_TOKEN_URI = 'https://idp.bexio.com/token';
const OAUTH2_REFRESH_TOKEN_URI = 'https://idp.bexio.com/token';

/**
* @var array $config
Expand Down Expand Up @@ -74,11 +74,6 @@ public function getRedirectUri()
return $this->config['redirectUri'];
}

public function getOrg()
{
return $this->accessToken['org'];
}

/**
* @param $accessToken
* @throws \Exception
Expand Down Expand Up @@ -229,40 +224,40 @@ protected function getRequest()
public function get($path, array $parameters = [])
{
$request = $this->getRequest();
$request->get(self::API_URL.'/'.$this->getOrg().'/'.$path, $parameters);
$request->get(self::API_URL.'/'.$path, $parameters);

return json_decode($request->response);
}

public function post($path, array $parameters = [])
{
$request = $this->getRequest();
$request->post(self::API_URL.'/'.$this->getOrg().'/'.$path, json_encode($parameters));
$request->post(self::API_URL.'/'.$path, json_encode($parameters));

return json_decode($request->response);
}

public function postWithoutPayload($path)
{
$request = $this->getRequest();
$request->post(self::API_URL.'/'.$this->getOrg().'/'.$path);
$request->post(self::API_URL.'/'.$path);

return json_decode($request->response);
}

public function put($path, array $parameters = [])
{
$request = $this->getRequest();
$request->put(self::API_URL.'/'.$this->getOrg().'/'.$path, $parameters);
$request->put(self::API_URL.'/'.$path, $parameters);

return json_decode($request->response);
}

public function delete($path, array $parameters = [])
{
$request = $this->getRequest();
$request->delete(self::API_URL.'/'.$this->getOrg().'/'.$path, $parameters);
$request->delete(self::API_URL.'/'.$path, $parameters);

return json_decode($request->response);
}
}
}

0 comments on commit 07f6abf

Please sign in to comment.