Skip to content

Commit 55a2504

Browse files
author
Felipe da Silva Pinheiro
committed
Added accept header
2 parents 0a1d5a6 + 1d5b214 commit 55a2504

File tree

13 files changed

+164
-145
lines changed

13 files changed

+164
-145
lines changed

Config/config.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22

33
return [
44
/*
5-
| Caminho para o arquivo da chave pública
5+
| path of the public key
66
*/
7-
'key' => env('KEY_PATH', storage_path('oauth-public.key')),
7+
'key' => env('KEY_PATH', storage_path('oauth-public.key')),
88

99
/*
10-
| URL do servidor OpenId
10+
| OpenID server URL
1111
*/
1212
'server' => env('AUTH_SERVER', 'https://devauth.univicosa.com.br'),
1313

1414
/*
15-
| Dados do cliente OpenId
15+
| OpenID client data
1616
*/
1717
'client' => [
1818

1919
/*
20-
| Id do cliente
20+
| Client ID
2121
*/
22-
'id' => env('CLIENT_ID'),
22+
'id' => env('CLIENT_ID'),
2323

2424
/*
25-
| Senha do cliente
25+
| Client secret
2626
*/
27-
'secret' => env('CLIENT_SECRET')
28-
]
27+
'secret' => env('CLIENT_SECRET'),
28+
],
2929

3030
];

Entities/User.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class User extends Authenticatable
99
{
1010
use Notifiable;
1111

12-
protected $connection = null;
12+
protected $connection = NULL;
1313

14-
public $incrementing = false;
14+
public $incrementing = FALSE;
1515

1616
protected $keyType = 'uuid';
1717

1818
protected $fillable = [
19-
'id', 'name', 'roles', 'registries', 'cpf', 'email', 'avatar'
19+
'id', 'name', 'roles', 'registries', 'cpf', 'email', 'avatar',
2020
];
2121
}

Guards/CustomSessionGuard.php

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CustomSessionGuard implements Guard
3939
*
4040
* @var bool
4141
*/
42-
protected $viaRemember = false;
42+
protected $viaRemember = FALSE;
4343

4444
/**
4545
* The session used by the guard.
@@ -74,27 +74,27 @@ class CustomSessionGuard implements Guard
7474
*
7575
* @var bool
7676
*/
77-
protected $loggedOut = false;
77+
protected $loggedOut = FALSE;
7878

7979
/**
8080
* Indicates if a token user retrieval has been attempted.
8181
*
8282
* @var bool
8383
*/
84-
protected $recallAttempted = false;
84+
protected $recallAttempted = FALSE;
8585

8686
/**
8787
* Create a new authentication guard.
8888
*
89-
* @param \Illuminate\Contracts\Session\Session $session
90-
* @param \Symfony\Component\HttpFoundation\Request $request
89+
* @param \Illuminate\Contracts\Session\Session $session
90+
* @param \Symfony\Component\HttpFoundation\Request $request
9191
*/
9292
public function __construct(Session $session,
93-
Request $request = null)
93+
Request $request = NULL)
9494
{
9595
$this->session = $session;
9696
$this->request = $request;
97-
$this->provider = null;
97+
$this->provider = NULL;
9898
}
9999

100100
/**
@@ -110,19 +110,21 @@ public function user()
110110
// If we've already retrieved the user for the current request we can just
111111
// return it back immediately. We do not want to fetch the user data on
112112
// every call to this method because that would be tremendously slow.
113-
if (! is_null($this->user)) {
113+
if (!is_null($this->user)) {
114114
if ($this->session->get('expires_at') < Carbon::now()) {
115115
$this->logout();
116+
116117
return NULL;
117118
}
119+
118120
return $this->user;
119121
}
120122
// First we will try to load the user using the identifier in the session if
121123
// one exists. Otherwise we will check for a "remember me" cookie in this
122124
// request, and if one exists, attempt to retrieve the user using that.
123125
$id = $this->session->get($this->getName());
124-
$user = null;
125-
if (! is_null($id)) {
126+
$user = NULL;
127+
if (!is_null($id)) {
126128
$token = $this->validateToken($id);
127129
if (!$token) {
128130
return NULL;
@@ -138,7 +140,7 @@ public function user()
138140
$user->email = $token->getClaim('email');
139141
}
140142
if ($token->hasClaim('roles')) {
141-
$user->roles = explode(' ', $token->getClaim('roles'));
143+
$user->roles = explode(' ', $token->getClaim('roles'));
142144
}
143145
if ($token->hasClaim('registries')) {
144146
$user->registries = explode(' ', $token->getClaim('registries'));
@@ -159,27 +161,28 @@ public function user()
159161

160162
/**
161163
* @param string $id
164+
*
162165
* @return \Lcobucci\JWT\Token|null
163166
*/
164167
public function validateToken(string $id)
165168
{
166169
$token = (new Parser())->parse((string)$id);
167170
//Verifica se o token expirou
168171
if ($token->isExpired()) {
169-
return null;
172+
return NULL;
170173
}
171174
//Verifica a assinatura
172175
$signer = new Sha256();
173176
$key = new Key('file://' . config('openid.key'));
174177
if (!$token->verify($signer, $key)) {
175-
return null;
178+
return NULL;
176179
}
177180
//Verifica os dados
178181
$validation = new ValidationData();
179182
$validation->setIssuer(config('openid.server'));
180183
$validation->setAudience(config('openid.client.id'));
181184
if (!$token->validate($validation)) {
182-
return null;
185+
return NULL;
183186
}
184187

185188
return $token;
@@ -204,13 +207,14 @@ public function id()
204207
/**
205208
* Update the session with the given ID.
206209
*
207-
* @param string $id
210+
* @param string $id
211+
*
208212
* @return void
209213
*/
210214
protected function updateSession($id)
211215
{
212216
$this->session->put($this->getName(), $id);
213-
$this->session->migrate(true);
217+
$this->session->migrate(TRUE);
214218
}
215219

216220
/**
@@ -231,8 +235,8 @@ public function logout()
231235
// Once we have fired the logout event we will clear the users out of memory
232236
// so they are no longer available as the user is no longer considered as
233237
// being signed into this application and should not be available here.
234-
$this->user = null;
235-
$this->loggedOut = true;
238+
$this->user = NULL;
239+
$this->loggedOut = TRUE;
236240
}
237241

238242
/**
@@ -248,11 +252,12 @@ protected function clearUserDataFromStorage()
248252
/**
249253
* Fire the login event if the dispatcher is set.
250254
*
251-
* @param \Illuminate\Contracts\Auth\Authenticatable $user
252-
* @param bool $remember
255+
* @param \Illuminate\Contracts\Auth\Authenticatable $user
256+
* @param bool $remember
257+
*
253258
* @return void
254259
*/
255-
protected function fireLoginEvent($user, $remember = false)
260+
protected function fireLoginEvent($user, $remember = FALSE)
256261
{
257262
if (isset($this->events)) {
258263
$this->events->dispatch(new Login($user, $remember));
@@ -262,7 +267,8 @@ protected function fireLoginEvent($user, $remember = false)
262267
/**
263268
* Fire the authenticated event if the dispatcher is set.
264269
*
265-
* @param \Illuminate\Contracts\Auth\Authenticatable $user
270+
* @param \Illuminate\Contracts\Auth\Authenticatable $user
271+
*
266272
* @return void
267273
*/
268274
protected function fireAuthenticatedEvent($user)
@@ -275,8 +281,9 @@ protected function fireAuthenticatedEvent($user)
275281
/**
276282
* Fire the failed authentication attempt event with the given arguments.
277283
*
278-
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
279-
* @param array $credentials
284+
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
285+
* @param array $credentials
286+
*
280287
* @return void
281288
*/
282289
protected function fireFailedEvent($user, array $credentials)
@@ -315,7 +322,7 @@ public function getName()
315322
*/
316323
public function getCookieJar()
317324
{
318-
if (! isset($this->cookie)) {
325+
if (!isset($this->cookie)) {
319326
throw new RuntimeException('Cookie jar has not been set.');
320327
}
321328

@@ -325,7 +332,8 @@ public function getCookieJar()
325332
/**
326333
* Set the cookie creator instance used by the guard.
327334
*
328-
* @param \Illuminate\Contracts\Cookie\QueueingFactory $cookie
335+
* @param \Illuminate\Contracts\Cookie\QueueingFactory $cookie
336+
*
329337
* @return void
330338
*/
331339
public function setCookieJar(CookieJar $cookie)
@@ -346,7 +354,8 @@ public function getDispatcher()
346354
/**
347355
* Set the event dispatcher instance.
348356
*
349-
* @param \Illuminate\Contracts\Events\Dispatcher $events
357+
* @param \Illuminate\Contracts\Events\Dispatcher $events
358+
*
350359
* @return void
351360
*/
352361
public function setDispatcher(Dispatcher $events)
@@ -370,16 +379,16 @@ public function getSession()
370379
* @return \Illuminate\Contracts\Auth\UserProvider
371380
*/
372381
public function getProvider()
373-
{
374-
return $this->provider;
375-
}
382+
{
383+
return $this->provider;
384+
}
376385

377386
/**
378387
* Set the user provider used by the guard.
379388
*
380-
* @param \Illuminate\Contracts\Auth\UserProvider|null $provider
389+
* @param \Illuminate\Contracts\Auth\UserProvider|null $provider
381390
*/
382-
public function setProvider(UserProvider $provider = null)
391+
public function setProvider(UserProvider $provider = NULL)
383392
{
384393
$this->provider = $provider;
385394
}
@@ -397,13 +406,14 @@ public function getUser()
397406
/**
398407
* Set the current user.
399408
*
400-
* @param \Illuminate\Contracts\Auth\Authenticatable $user
409+
* @param \Illuminate\Contracts\Auth\Authenticatable $user
410+
*
401411
* @return $this
402412
*/
403413
public function setUser(AuthenticatableContract $user)
404414
{
405415
$this->user = $user;
406-
$this->loggedOut = false;
416+
$this->loggedOut = FALSE;
407417
$this->fireAuthenticatedEvent($user);
408418

409419
return $this;
@@ -422,7 +432,8 @@ public function getRequest()
422432
/**
423433
* Set the current request instance.
424434
*
425-
* @param \Symfony\Component\HttpFoundation\Request $request
435+
* @param \Symfony\Component\HttpFoundation\Request $request
436+
*
426437
* @return $this
427438
*/
428439
public function setRequest(Request $request)
@@ -436,10 +447,11 @@ public function setRequest(Request $request)
436447
* Validate a user's credentials.
437448
*
438449
* @param array $credentials
450+
*
439451
* @return bool
440452
*/
441453
public function validate(array $credentials = [])
442454
{
443-
return true;
455+
return TRUE;
444456
}
445457
}

0 commit comments

Comments
 (0)