protected function getValidTokenPayload(Request $request) { // try to get a token first from the Authorization header, then from the GET and POST vars $headers = $request->Headers; $getToken = $request->Get('AuthToken'); $postToken = $request->Post('AuthToken'); if (isset($headers['Authorization']) && substr($headers['Authorization'], 0, 7) === 'Bearer ') { $tokenString = substr($headers['Authorization'], 7); } elseif (isset($getToken)) { $tokenString = $getToken; } elseif (isset($postToken)) { $tokenString = $postToken; } else { $tokenString = null; } if (isset($tokenString)) { try { return \Firebase\JWT\JWT::decode($tokenString, $this->secretKey, ['HS256']); } catch (ExpiredException $e) { return 'expired'; } catch (\Exception $e) { return null; } } else { return null; } }
/** * Will return the request's data as an array from whatever source it can find. * Can be called in child classes to modify the contents of the data before saving. * @param Request $request * @return array */ protected function getPostData(Request $request) { if (!isset($this->postData)) { $body = $request->Body; /** @var array $postVars */ $postVars = $request->Post(); if (isset($postVars['model'])) { $this->postData = json_decode($postVars['model'], true); } elseif (!empty($postVars)) { $this->postData = $postVars; } elseif (strlen($body) > 0) { $this->postData = json_decode($body, true); } else { $this->postData = []; } } return $this->postData; }