-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOauth.php
174 lines (156 loc) · 3.91 KB
/
Oauth.php
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* Arikaim
*
* @link http://www.arikaim.com
* @copyright Copyright (c) Konstantin Atanasov <info@arikaim.com>
* @license http://www.arikaim.com/license
*
*/
namespace Arikaim\Modules\Oauth;
use League\OAuth1\Client\Credentials\TemporaryCredentials;
use Arikaim\Core\Http\Session;
use Arikaim\Core\Extension\Module;
/**
* Oauth module class
*/
class Oauth extends Module
{
/**
* Provider reference
*
* @var object
*/
private $provider = null;
/**
* Install module
*
* @return void
*/
public function install()
{
$this->installDriver('Arikaim\\Modules\\Oauth\\Drivers\\TwitterOauthDriver');
$this->installDriver('Arikaim\\Modules\\Oauth\\Drivers\\GithubOauthDriver');
$this->installDriver('Arikaim\\Modules\\Oauth\\Drivers\\GoogleOauthDriver');
$this->installDriver('Arikaim\\Modules\\Oauth\\Drivers\\FacebookOauthDriver');
$this->installDriver('Arikaim\\Modules\\Oauth\\Drivers\\StripeOauthDriver');
$this->installDriver('Arikaim\\Modules\\Oauth\\Drivers\\SquareOauthDriver');
}
/**
* Get temporary credentials from session
*
* @return TemporaryCredentials
*/
public function getTemporaryCredentials()
{
$identifier = Session::get('oauth.temp.identifier',null);
$secret = Session::get('oauth.temp.secret',null);
$credentials = new TemporaryCredentials();
$credentials->setIdentifier($identifier);
$credentials->setSecret($secret);
return $credentials;
}
/**
* Save OAuth2 action
*
* @param string $action
* @return void
*/
public function saveAction($action): void
{
Session::set('oauth.action',$action);
}
/**
* Get OAuth2 action
*
* @return mixed
*/
public function getAction()
{
return Session::get('oauth.action');
}
/**
* Clear OAuth2 action
*
* @return void
*/
public function clearAction(): void
{
Session::remove('oauth.action');
}
/**
* Save OAuth2 state
*
* @param string $state
* @return void
*/
public function saveState($state): void
{
Session::set('oauth.state',$state);
}
/**
* Get OAuth2 state
*
* @return string|null
*/
public function getState()
{
return Session::get('oauth.state',null);
}
/**
* Clear OAuth2 state
*
* @return void
*/
public function clearState()
{
Session::remove('oauth.state');
}
/**
* Save temporary credentials to session
*
* @param TemporaryCredentials $credentials
* @return void
*/
public function saveTemporaryCredentials($credentials)
{
// store credentials
Session::set('oauth.temp.identifier',$credentials->getIdentifier());
Session::set('oauth.temp.secret',$credentials->getSecret());
}
/**
* Clear temporary credentials from session
*
* @return TemporaryCredentials
*/
public function clearTemporaryCredentials()
{
Session::remove('oauth.temp.identifier');
Session::remove('oauth.temp.secret');
}
/**
* Create provider
*
* @param string $providerClass
* @param array $options
* @param array $collaborators
* @return void
*/
public function create($providerClass = null, array $options = [], array $collaborators = [])
{
if ($providerClass == null || empty($providerClass) == true) {
$providerClass = "League\OAuth2\Client\Provider\GenericProvider";
}
$this->provider = new $providerClass($options,$collaborators);
return \is_object($this->provider);
}
/**
* Get provider
*
* @return object
*/
public function getProvider()
{
return $this->provider;
}
}