Skip to content

Commit ad68c6c

Browse files
Merge pull request appwrite#3016 from appwrite/feat-zoom-oauth
2 parents 6e1b41c + 2a18857 commit ad68c6c

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed

app/config/providers.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@
231231
'beta' => false,
232232
'mock' => false,
233233
],
234+
'zoom' => [
235+
'name' => 'Zoom',
236+
'developers' => 'https://marketplace.zoom.us/docs/guides/auth/oauth/',
237+
'icon' => 'icon-zoom',
238+
'enabled' => true,
239+
'sandbox' => false,
240+
'form' => false,
241+
'beta' => false,
242+
'mock' => false,
243+
],
234244
'yahoo' => [
235245
'name' => 'Yahoo',
236246
'developers' => 'https://developer.yahoo.com/oauth2/guide/flows_authcode/',

public/images/users/zoom.png

15.2 KB
Loading

src/Appwrite/Auth/OAuth2/Zoom.php

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?php
2+
3+
namespace Appwrite\Auth\OAuth2;
4+
5+
use Appwrite\Auth\OAuth2;
6+
7+
class Zoom extends OAuth2
8+
{
9+
/**
10+
* @var string
11+
*/
12+
private $endpoint = 'https://zoom.us';
13+
14+
/**
15+
* @var string
16+
*/
17+
private $version = '2022-03-26';
18+
19+
/**
20+
* @var array
21+
*/
22+
protected $user = [];
23+
24+
/**
25+
* @var array
26+
*/
27+
protected $tokens = [];
28+
29+
/**
30+
* @var array
31+
*/
32+
protected $scopes = [
33+
'user_profile'
34+
];
35+
36+
/**
37+
* @return string
38+
*/
39+
public function getName():string
40+
{
41+
return 'zoom';
42+
}
43+
44+
/**
45+
* @return string
46+
*/
47+
public function getLoginURL():string
48+
{
49+
return $this->endpoint . '/oauth/authorize?'. \http_build_query([
50+
'client_id' => $this->appID,
51+
'redirect_uri' => $this->callback,
52+
'response_type' => 'code',
53+
'scope' => \implode(' ', $this->getScopes()),
54+
'state' => \json_encode($this->state),
55+
]);
56+
}
57+
58+
/**
59+
* @param string $code
60+
*
61+
* @return array
62+
*/
63+
protected function getTokens(string $code): array
64+
{
65+
if(empty($this->tokens)) {
66+
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret), 'Content-Type: application/x-www-form-urlencoded'];
67+
$this->tokens = \json_decode($this->request(
68+
'POST',
69+
$this->endpoint . '/oauth/token',
70+
$headers,
71+
\http_build_query([
72+
'grant_type' => 'authorization_code',
73+
'redirect_uri' => $this->callback,
74+
'code' => $code
75+
])
76+
), true);
77+
}
78+
79+
return $this->tokens;
80+
}
81+
82+
/**
83+
* @param string $refreshToken
84+
*
85+
* @return array
86+
*/
87+
public function refreshTokens(string $refreshToken):array
88+
{
89+
$headers = ['Authorization: Basic ' . \base64_encode($this->appID . ':' . $this->appSecret), 'Content-Type: application/x-www-form-urlencoded'];
90+
$this->tokens = \json_decode($this->request(
91+
'POST',
92+
$this->endpoint . '/oauth/token',
93+
$headers,
94+
\http_build_query([
95+
'grant_type' => 'refresh_token',
96+
'refresh_token' => $refreshToken,
97+
])
98+
), true);
99+
100+
if(empty($this->tokens['refresh_token'])) {
101+
$this->tokens['refresh_token'] = $refreshToken;
102+
}
103+
104+
return $this->tokens;
105+
}
106+
107+
/**
108+
* @param $accessToken
109+
*
110+
* @return string
111+
*/
112+
public function getUserID(string $accessToken):string
113+
{
114+
$response = $this->getUser($accessToken);
115+
return $response['id'] ?? '';
116+
}
117+
118+
/**
119+
* @param $accessToken
120+
*
121+
* @return string
122+
*/
123+
public function getUserEmail(string $accessToken):string
124+
{
125+
$response = $this->getUser($accessToken);
126+
return $response['email'] ?? '';
127+
}
128+
129+
/**
130+
* @param $accessToken
131+
*
132+
* @return string
133+
*/
134+
public function getUserName(string $accessToken):string
135+
{
136+
$response = $this->getUser($accessToken);
137+
return ($response['first_name'] ?? '') . ' ' . ($response['last_name'] ?? '');
138+
}
139+
140+
/**
141+
* @param string $accessToken
142+
*
143+
* @return array
144+
*/
145+
protected function getUser(string $accessToken)
146+
{
147+
$headers = [
148+
'Authorization: Bearer '.\urlencode($accessToken)
149+
];
150+
151+
if (empty($this->user)) {
152+
$this->user = \json_decode($this->request('GET', 'https://api.zoom.us/v2/users/me', $headers), true);
153+
}
154+
155+
return $this->user;
156+
}
157+
}

0 commit comments

Comments
 (0)