1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Resta\Authenticate;
|
4
|
|
|
|
5
|
|
|
class ConfigProvider
|
6
|
|
|
{
|
7
|
|
|
/**
|
8
|
|
|
* @var string
|
9
|
|
|
*/
|
10
|
|
|
protected $driverDefaultNamespace = "\Resta\Authenticate\Driver";
|
11
|
|
|
|
12
|
|
|
/**
|
13
|
|
|
* @var string $store
|
14
|
|
|
*/
|
15
|
|
|
protected $store = 'session';
|
16
|
|
|
|
17
|
|
|
/**
|
18
|
|
|
* @var null|mixed
|
19
|
|
|
*/
|
20
|
|
|
protected $config;
|
21
|
|
|
|
22
|
|
|
/**
|
23
|
|
|
* @var string
|
24
|
|
|
*/
|
25
|
|
|
protected $driver;
|
26
|
|
|
|
27
|
|
|
/**
|
28
|
|
|
* ConfigProvider constructor.
|
29
|
|
|
*/
|
30
|
|
|
public function __construct()
|
31
|
|
|
{
|
32
|
|
|
$this->config();
|
33
|
|
|
|
34
|
|
|
if($this->guard=="default"){
|
35
|
|
|
$this->setAuthenticateNeeds();
|
36
|
|
|
}
|
37
|
|
|
|
38
|
|
|
$this->table();
|
39
|
|
|
}
|
40
|
|
|
|
41
|
|
|
/**
|
42
|
|
|
* get authenticate config values
|
43
|
|
|
*
|
44
|
|
|
* @return void|mixed
|
45
|
|
|
*/
|
46
|
|
|
public function config()
|
47
|
|
|
{
|
48
|
|
|
$this->config = config('authenticate');
|
49
|
|
|
|
50
|
|
|
return $this->config;
|
51
|
|
|
}
|
52
|
|
|
|
53
|
|
|
/**
|
54
|
|
|
* auth client query
|
55
|
|
|
*
|
56
|
|
|
* @return string
|
57
|
|
|
*/
|
58
|
|
|
public function getAddToWhere()
|
59
|
|
|
{
|
60
|
|
|
if(isset($this->config['guard'][$this->guard]['addToWhere'])){
|
61
|
|
|
return $this->config['guard'][$this->guard]['addToWhere'];
|
62
|
|
|
}
|
63
|
|
|
return null;
|
64
|
|
|
}
|
65
|
|
|
|
66
|
|
|
/**
|
67
|
|
|
* get config token
|
68
|
|
|
*
|
69
|
|
|
* @return string
|
70
|
|
|
*/
|
71
|
|
|
public function getConfigToken()
|
72
|
|
|
{
|
73
|
|
|
if(isset($this->config['guard'][$this->guard]['token'])){
|
74
|
|
|
return $this->config['guard'][$this->guard]['token'];
|
75
|
|
|
}
|
76
|
|
|
return null;
|
77
|
|
|
}
|
78
|
|
|
|
79
|
|
|
/**
|
80
|
|
|
* get credentials
|
81
|
|
|
*
|
82
|
|
|
* @return string
|
83
|
|
|
*/
|
84
|
|
|
public function getCredentials()
|
85
|
|
|
{
|
86
|
|
|
return $this->config['guard'][$this->guard]['credentials'];
|
87
|
|
|
}
|
88
|
|
|
|
89
|
|
|
/**
|
90
|
|
|
* get driver builder namespace
|
91
|
|
|
*
|
92
|
|
|
* @return string
|
93
|
|
|
*/
|
94
|
|
|
public function getDriverBuilderNamespace()
|
95
|
|
|
{
|
96
|
|
|
return $this->driverDefaultNamespace.'\\'.$this->getDriver().'\\UserBuilder';
|
97
|
|
|
}
|
98
|
|
|
|
99
|
|
|
/**
|
100
|
|
|
* get driver for authenticate
|
101
|
|
|
*
|
102
|
|
|
* @return string
|
103
|
|
|
*/
|
104
|
|
|
public function getDriver()
|
105
|
|
|
{
|
106
|
|
|
return 'Eloquent';
|
107
|
|
|
}
|
108
|
|
|
|
109
|
|
|
/**
|
110
|
|
|
* get driver namespace
|
111
|
|
|
*
|
112
|
|
|
* @return string
|
113
|
|
|
*/
|
114
|
|
|
public function getDriverNamespace()
|
115
|
|
|
{
|
116
|
|
|
return $this->driverDefaultNamespace.'\\'.$this->getDriver().'\\User';
|
117
|
|
|
}
|
118
|
|
|
|
119
|
|
|
/**
|
120
|
|
|
* get expire for authenticate
|
121
|
|
|
*
|
122
|
|
|
* @return mixed
|
123
|
|
|
*/
|
124
|
|
|
public function getExpire()
|
125
|
|
|
{
|
126
|
|
|
return $this->config['guard'][$this->guard]['expire'];
|
127
|
|
|
}
|
128
|
|
|
|
129
|
|
|
/**
|
130
|
|
|
* get http for authenticate
|
131
|
|
|
*
|
132
|
|
|
* @return string
|
133
|
|
|
*/
|
134
|
|
|
public function getHttp()
|
135
|
|
|
{
|
136
|
|
|
return $this->config['guard'][$this->guard]['http'];
|
137
|
|
|
}
|
138
|
|
|
|
139
|
|
|
/**
|
140
|
|
|
* get request for authenticate
|
141
|
|
|
*
|
142
|
|
|
* @return string
|
143
|
|
|
*/
|
144
|
|
|
public function getRequest()
|
145
|
|
|
{
|
146
|
|
|
return ucfirst($this->config['guard'][$this->guard]['request']);
|
147
|
|
|
}
|
148
|
|
|
|
149
|
|
|
/**
|
150
|
|
|
* get token key for authenticate
|
151
|
|
|
*
|
152
|
|
|
* @return string
|
153
|
|
|
*/
|
154
|
|
|
public function getTokenKey()
|
155
|
|
|
{
|
156
|
|
|
return $this->config['guard'][$this->guard]['key'];
|
157
|
|
|
}
|
158
|
|
|
|
159
|
|
|
/**
|
160
|
|
|
* get provider for authenticate
|
161
|
|
|
*
|
162
|
|
|
* @param $key
|
163
|
|
|
* @return mixed|null
|
164
|
|
|
*/
|
165
|
|
|
public function provider($key)
|
166
|
|
|
{
|
167
|
|
|
if(app()->has('authenticate.'.$key) && is_callable($provider = app()->get('authenticate.'.$key))){
|
168
|
|
|
return $provider;
|
169
|
|
|
}
|
170
|
|
|
|
171
|
|
|
return null;
|
172
|
|
|
}
|
173
|
|
|
|
174
|
|
|
/**
|
175
|
|
|
* set authenticate needs
|
176
|
|
|
*
|
177
|
|
|
* @return void|mixed
|
178
|
|
|
*/
|
179
|
|
|
protected function setAuthenticateNeeds()
|
180
|
|
|
{
|
181
|
|
|
$this->getDriver();
|
182
|
|
|
}
|
183
|
|
|
|
184
|
|
|
/**
|
185
|
|
|
* store for authenticate
|
186
|
|
|
*
|
187
|
|
|
* @param $store
|
188
|
|
|
* @return $this
|
189
|
|
|
*/
|
190
|
|
|
public function store($store)
|
191
|
|
|
{
|
192
|
|
|
$this->store = $store;
|
193
|
|
|
|
194
|
|
|
return $this;
|
195
|
|
|
}
|
196
|
|
|
|
197
|
|
|
/**
|
198
|
|
|
* table name for authenticate
|
199
|
|
|
*
|
200
|
|
|
* @return string
|
201
|
|
|
*/
|
202
|
|
|
public function table()
|
203
|
|
|
{
|
204
|
|
|
$table = $this->config['guard'][$this->guard]['table'];
|
205
|
|
|
|
206
|
|
|
app()->register('authenticateTable',$table);
|
207
|
|
|
}
|
208
|
|
|
|
209
|
|
|
} |