Skip to content

Commit a3de2af

Browse files
committed
Changed Auth method from JWT to Server-to-Server OAuth
1 parent 2f01cb4 commit a3de2af

File tree

9 files changed

+72
-45
lines changed

9 files changed

+72
-45
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Add the following repository source to your composer.json:
1515
Require via composer:
1616

1717
```
18-
composer require usabilitydynamics/zoom-api-php-client:0.0.3
18+
composer require usabilitydynamics/zoom-api-php-client:0.0.12
1919
```
2020

2121
Initialize:
2222

2323
```
2424
use UDX\Zoom\Zoom;
25-
$zoom = new Zoom( <api_key>, <secret_key> );
25+
$zoom = new Zoom( <account_id>, <client_id>, <client_secret> );
2626
```
2727

2828
Use:

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
"require": {
1515
"php": ">=7.4",
16-
"guzzlehttp/guzzle": "~7.0",
17-
"firebase/php-jwt": "^6.4.0"
16+
"guzzlehttp/guzzle": "~7.0"
1817
},
1918

2019
"autoload": {

src/Endpoint/Meetings.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ class Meetings extends Request {
1212

1313
/**
1414
* Meetings constructor.
15-
* @param $apiKey
16-
* @param $apiSecret
15+
* @param $accountId
16+
* @param $clientId
17+
* @param $clientSecret
1718
*/
18-
public function __construct($apiKey, $apiSecret) {
19-
parent::__construct($apiKey, $apiSecret);
19+
public function __construct( $accountId, $clientId, $clientSecret ) {
20+
parent::__construct( $accountId, $clientId, $clientSecret );
2021
}
2122

2223
/**

src/Endpoint/Recordings.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ class Recordings extends Request {
1212

1313
/**
1414
* Recordings constructor.
15-
* @param $apiKey
16-
* @param $apiSecret
15+
* @param $accountId
16+
* @param $clientId
17+
* @param $clientSecret
1718
*/
18-
public function __construct($apiKey, $apiSecret) {
19-
parent::__construct($apiKey, $apiSecret);
19+
public function __construct( $accountId, $clientId, $clientSecret ) {
20+
parent::__construct( $accountId, $clientId, $clientSecret );
2021
}
2122

2223
/**

src/Endpoint/Reports.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
class Reports extends Request {
1212

1313
/**
14-
* Meetings constructor.
15-
* @param $apiKey
16-
* @param $apiSecret
14+
* Reports constructor.
15+
* @param $accountId
16+
* @param $clientId
17+
* @param $clientSecret
1718
*/
18-
public function __construct($apiKey, $apiSecret) {
19-
parent::__construct($apiKey, $apiSecret);
19+
public function __construct( $accountId, $clientId, $clientSecret ) {
20+
parent::__construct( $accountId, $clientId, $clientSecret );
2021
}
2122

2223
/**

src/Endpoint/Users.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ class Users extends Request {
1212

1313
/**
1414
* Users constructor.
15-
* @param $apiKey
16-
* @param $apiSecret
15+
* @param $accountId
16+
* @param $clientId
17+
* @param $clientSecret
1718
*/
18-
public function __construct($apiKey, $apiSecret) {
19-
parent::__construct($apiKey, $apiSecret);
19+
public function __construct( $accountId, $clientId, $clientSecret ) {
20+
parent::__construct( $accountId, $clientId, $clientSecret );
2021
}
2122

2223
/**

src/Http/Request.php

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace UDX\Zoom\Http;
44

5-
use Firebase\JWT\JWT;
65
use GuzzleHttp\Client;
76
use GuzzleHttp\Exception\ClientException;
87
use GuzzleHttp\Psr7\Response;
@@ -12,12 +11,17 @@ class Request {
1211
/**
1312
* @var
1413
*/
15-
protected $apiKey;
14+
protected $accountId;
1615

1716
/**
1817
* @var
1918
*/
20-
protected $apiSecret;
19+
protected $clientId;
20+
21+
/**
22+
* @var
23+
*/
24+
protected $clientSecret;
2125

2226
/**
2327
* @var Client
@@ -29,15 +33,24 @@ class Request {
2933
*/
3034
public $apiPoint = 'https://api.zoom.us/v2/';
3135

36+
/**
37+
* @var string
38+
*/
39+
public $oauthPoint = 'https://zoom.us/oauth/token?grant_type=account_credentials&account_id=';
40+
41+
3242
/**
3343
* Request constructor.
34-
* @param $apiKey
35-
* @param $apiSecret
44+
* @param $accountId
45+
* @param $clientId
46+
* @param $clientSecret
3647
*/
37-
public function __construct( $apiKey, $apiSecret ) {
38-
$this->apiKey = $apiKey;
48+
public function __construct( $accountId, $clientId, $clientSecret ) {
49+
$this->accountId = $accountId;
3950

40-
$this->apiSecret = $apiSecret;
51+
$this->clientId = $clientId;
52+
53+
$this->clientSecret = $clientSecret;
4154

4255
$this->client = new Client();
4356
}
@@ -49,24 +62,28 @@ public function __construct( $apiKey, $apiSecret ) {
4962
*/
5063
protected function headers(): array {
5164
return [
52-
'Authorization' => 'Bearer ' . $this->generateJWT(),
65+
'Authorization' => 'Bearer ' . $this->generateOAuthToken(),
5366
'Content-Type' => 'application/json',
5467
'Accept' => 'application/json',
5568
];
5669
}
5770

5871
/**
59-
* Generate J W T
72+
* Generate OAuth token
6073
*
6174
* @return string
6275
*/
63-
protected function generateJWT() {
64-
$token = [
65-
'iss' => $this->apiKey,
66-
'exp' => time() + 60,
67-
];
76+
protected function generateOAuthToken() {
77+
try {
78+
$response = $this->client->request('POST', $this->oauthPoint . $this->accountId, [
79+
'auth' => [ $this->clientId, $this->clientSecret ]
80+
]);
81+
$result = $this->result($response);
82+
return isset($result['access_token']) ? $result['access_token'] : '';
6883

69-
return JWT::encode($token, $this->apiSecret, 'HS256');
84+
} catch (ClientException $e) {
85+
return (array)json_decode($e->getResponse()->getBody()->getContents());
86+
}
7087
}
7188

7289

src/Zoom.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,30 @@ class Zoom {
88
/**
99
* @var null
1010
*/
11-
private $apiKey = null;
11+
private $accountId = null;
1212

1313
/**
1414
* @var null
1515
*/
16-
private $apiSecret = null;
16+
private $clientId = null;
17+
18+
/**
19+
* @var null
20+
*/
21+
private $clientSecret = null;
1722

1823
/**
1924
* Zoom constructor.
2025
* @param $apiKey
2126
* @param $apiSecret
2227
*/
23-
public function __construct( $apiKey, $apiSecret ) {
28+
public function __construct( $accountId, $clientId, $clientSecret ) {
29+
30+
$this->accountId = $accountId;
2431

25-
$this->apiKey = $apiKey;
32+
$this->clientId = $clientId;
2633

27-
$this->apiSecret = $apiSecret;
34+
$this->clientSecret = $clientSecret;
2835
}
2936

3037
/**
@@ -58,7 +65,7 @@ public function make( $resource ) {
5865

5966
$class = 'UDX\\Zoom\\Endpoint\\' . ucfirst(strtolower($resource));
6067
if (class_exists($class)) {
61-
return new $class( $this->apiKey, $this->apiSecret );
68+
return new $class( $this->accountId, $this->clientId, $this->clientSecret );
6269
}
6370
throw new Exception('Wrong method');
6471
}

tests/Bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Bootstrap extends TestCase {
1414
*/
1515
public function testClientCreate() {
1616
try {
17-
$client = new Zoom\Zoom('key', 'secret');
17+
$client = new Zoom\Zoom('id', 'key', 'secret');
1818
$this->assertInstanceOf(Zoom\Zoom::class, $client);
1919
} catch ( Exception $e ) {
2020
$this->fail( $e );
@@ -27,7 +27,7 @@ public function testClientCreate() {
2727
*/
2828
public function testMeetingsEndpoint() {
2929
try {
30-
$client = new Zoom\Zoom( 'key', 'secret' );
30+
$client = new Zoom\Zoom( 'id', 'key', 'secret' );
3131
$this->assertInstanceOf(Zoom\Endpoint\Meetings::class, $client->meetings);
3232
$this->assertInstanceOf(Zoom\Http\Request::class, $client->meetings);
3333
$this->assertTrue( method_exists( $client->meetings, 'list' ),

0 commit comments

Comments
 (0)