Proyectos de Subversion LeadersLinked - Services

Rev

Rev 106 | Rev 108 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 106 Rev 107
Línea 414... Línea 414...
414
                    'data'   => $messages
414
                    'data'   => $messages
415
                ]);
415
                ]);
416
            }
416
            }
417
        } else if ($request->isGet()) {
417
        } else if ($request->isGet()) {
Línea -... Línea 418...
-
 
418
            
418
            
419
            $jwtToken = null;
Línea 419... Línea -...
419
            $aes = Functions::generatePassword(16);
-
 
420
            
-
 
Línea -... Línea 420...
-
 
420
            $headers = getallheaders();
-
 
421
            
-
 
422
            
-
 
423
            if(!empty($headers['authorization']) || !empty($headers['Authorization'])) {
-
 
424
                
-
 
425
                $token = trim(empty($headers['authorization']) ? $headers['Authorization'] : $headers['authorization']);
-
 
426
                
-
 
427
                
-
 
428
                if (substr($token, 0, 6 ) == 'Bearer') {
-
 
429
                    
-
 
430
                    $token = trim(substr($token, 7));
-
 
431
                    
-
 
432
                    if(!empty($this->config['leaderslinked.jwt.key'])) {
-
 
433
                        $key = $this->config['leaderslinked.jwt.key'];
-
 
434
                        
-
 
435
                        
-
 
436
                        try {
-
 
437
                            $payload = JWT::decode($token, new Key($key, 'HS256'));
-
 
438
                            
-
 
439
                            
-
 
440
                            if(empty($payload->iss) || $payload->iss != $_SERVER['HTTP_HOST']) {
-
 
441
                                return new JsonModel(['success' => false, 'data' => 'Unauthorized - JWT - Wrong server',  'fatal'  => true]);
421
            $jwtToken = new JwtToken();
442
                            }
-
 
443
                            
422
            $jwtToken->aes = $aes;
444
                            $uuid = empty($payload->uuid) ? '' : $payload->uuid;
423
            
445
                            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
-
 
446
                            $jwtToken = $jwtTokenMapper->fetchOneByUuid($uuid);
-
 
447
                        } catch(\Exception $e) {
-
 
448
                            //Token invalido
424
            $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
449
                        }
Línea 425... Línea 450...
425
            if($jwtTokenMapper->insert($jwtToken)) {
450
                    }
Línea 426... Línea -...
426
                $jwtToken = $jwtTokenMapper->fetchOne($jwtToken->id);
-
 
427
            }
451
                }
428
            
-
 
-
 
452
            }
429
            $token = '';
453
            
430
            
454
            if(!$jwtToken) {
431
            if(!empty($this->config['leaderslinked.jwt.key'])) {
-
 
432
                $issuedAt   = new \DateTimeImmutable();
-
 
433
                $expire     = $issuedAt->modify('+24 hours')->getTimestamp();
-
 
434
                $serverName = $_SERVER['HTTP_HOST'];
-
 
435
                $payload = [
-
 
436
                    'iat'  => $issuedAt->getTimestamp(),
-
 
Línea -... Línea 455...
-
 
455
            
-
 
456
                $aes = Functions::generatePassword(16);
-
 
457
                
-
 
458
                $jwtToken = new JwtToken();
Línea -... Línea 459...
-
 
459
                $jwtToken->aes = $aes;
-
 
460
                
-
 
461
                $jwtTokenMapper = JwtTokenMapper::getInstance($this->adapter);
-
 
462
                if($jwtTokenMapper->insert($jwtToken)) {
-
 
463
                    $jwtToken = $jwtTokenMapper->fetchOne($jwtToken->id);
-
 
464
                }
-
 
465
                
-
 
466
                $token = '';
-
 
467
                
-
 
468
                if(!empty($this->config['leaderslinked.jwt.key'])) {
-
 
469
                    $issuedAt   = new \DateTimeImmutable();
-
 
470
                    $expire     = $issuedAt->modify('+24 hours')->getTimestamp();
-
 
471
                    $serverName = $_SERVER['HTTP_HOST'];
-
 
472
                    $payload = [
-
 
473
                        'iat'  => $issuedAt->getTimestamp(),
437
                    'iss'  => $serverName,
474
                        'iss'  => $serverName,
438
                    'nbf'  => $issuedAt->getTimestamp(),
475
                        'nbf'  => $issuedAt->getTimestamp(),
-
 
476
                        'exp'  => $expire,
439
                    'exp'  => $expire,
477
                        'uuid' => $jwtToken->uuid,
Línea -... Línea 478...
-
 
478
                    ];
-
 
479
                    
Línea 440... Línea 480...
440
                    'uuid' => $jwtToken->uuid,
480
                    
441
                ];
481
                    $key = $this->config['leaderslinked.jwt.key'];
442
                
482
                    $token = JWT::encode($payload, $key, 'HS256');
Línea 478... Línea 518...
478
                'access_usign_social_networks'  => $access_usign_social_networks && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
518
                'access_usign_social_networks'  => $access_usign_social_networks && $currentNetwork->default == Network::DEFAULT_YES ? 'y' : 'n',
479
                'logo_url'                      => $this->url()->fromRoute('storage-network', ['type' => 'logo'],['force_canonical' => true]),
519
                'logo_url'                      => $this->url()->fromRoute('storage-network', ['type' => 'logo'],['force_canonical' => true]),
480
                'navbar_url'                    => $this->url()->fromRoute('storage-network', ['type' => 'navbar'],['force_canonical' => true]),
520
                'navbar_url'                    => $this->url()->fromRoute('storage-network', ['type' => 'navbar'],['force_canonical' => true]),
481
                'favico_url'                    => $this->url()->fromRoute('storage-network', ['type' => 'favico'],['force_canonical' => true]),
521
                'favico_url'                    => $this->url()->fromRoute('storage-network', ['type' => 'favico'],['force_canonical' => true]),
482
                'intro'                         => $currentNetwork->intro,
522
                'intro'                         => $currentNetwork->intro,
483
                'is_logged_in'                  => false
523
                'is_logged_in'                  => $jwtToken->user_id ? true : false,
Línea 484... Línea 524...
484
 
524
 
Línea 485... Línea 525...
485
            ];
525
            ];
486
            
526