forked from Weezevent/socialite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProvider.php
More file actions
86 lines (67 loc) · 2.45 KB
/
Provider.php
File metadata and controls
86 lines (67 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Opentickettech\Socialite;
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
use SocialiteProviders\Manager\OAuth2\User;
class Provider extends AbstractProvider
{
const IDENTIFIER = "OPENTICKETTECH";
public function getAccessTokenRefreshResponse ($refreshToken) {
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
"headers" => ["Accept" => "application/json"],
"form_params" => $this->getTokenRefreshFields($refreshToken),
]);
return json_decode($response->getBody(), true);
}
protected function getAuthUrl ($state) {
$baseUrl = config("services.opentickettech.uri", "https://auth.openticket.tech");
return $this->buildAuthUrlFromBase(rtrim($baseUrl, "/") . "/token/authorize", $state);
}
protected function getTokenUrl () {
$baseUrl = config("services.opentickettech.uri", "https://auth.openticket.tech");
return rtrim($baseUrl, "/") . "/token";
}
public function userFromToken($token) {
return $this->getUserByToken($token);
}
protected function getUserByToken ($token) {
$baseUrl = config("services.opentickettech.uri", "https://auth.openticket.tech");
$userUrl = rtrim($baseUrl, "/") . "/user/me";
$response = $this->getHttpClient()->get(
$userUrl, $this->getRequestOptions($token)
);
$user = json_decode($response->getBody(), true);
return $user;
}
protected function mapUserToObject (array $user) {
// TODO - Implement
throw new \BadMethodCallException("This function has not been implemented yet");
}
protected function getTokenFields ($code) {
return array_merge(parent::getTokenFields($code), [
"grant_type" => "authorization_code",
]);
}
protected function getTokenRefreshFields ($refreshToken) {
return [
"client_id" => $this->clientId,
"client_secret" => $this->clientSecret,
"refresh_token" => $refreshToken,
"grant_type" => "refresh_token",
];
}
/**
* Get the default options for an HTTP request.
*
* @param string $token
* @return array
*/
protected function getRequestOptions($token)
{
return [
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$token,
],
];
}
}