Compare commits

..

No commits in common. "master" and "1.0.2" have entirely different histories.

4 changed files with 15 additions and 50 deletions

View File

@ -17,8 +17,7 @@
} }
}, },
"require": { "require": {
"php" : "^7.0", "meta-tech/pws-auth" : "^2.1",
"meta-tech/pws-auth" : "@dev",
"meta-tech/silex-controller-service" : "^1.0", "meta-tech/silex-controller-service" : "^1.0",
"silex/silex": "^2.0", "silex/silex": "^2.0",
"gecko-packages/gecko-silex-config-service": "^2.0", "gecko-packages/gecko-silex-config-service": "^2.0",

View File

@ -51,17 +51,6 @@ abstract class Base implements ControllerProviderInterface
} }
/*!
* @method routing
* @public
* @param Silex\ControllerCollection $collection
* @return Silex\ControllerCollection
*/
public function routing(ControllerCollection $collection) : ControllerCollection
{
return $collection;
}
/*! /*!
* @method connect * @method connect
* @public * @public

View File

@ -98,10 +98,8 @@ class Authentication
$done = false; $done = false;
$msg = 'authentication require'; $msg = 'authentication require';
$token = $this->authenticator->getToken(); $token = $this->authenticator->getToken();
$login = $request->get('login');
$responseToken = $this->authenticator->generateResponseHeader($token);
$headers = $this->getResponseHeaders([], $responseToken);
if ($this->authenticator->isValid($token)) { if ($this->authenticator->isValid($token)) {
$login = $request->get('login');
$password = $request->get('password'); $password = $request->get('password');
if ($this->authenticator->check($token, $login)) { if ($this->authenticator->check($token, $login)) {
try { try {
@ -119,21 +117,7 @@ class Authentication
if (!$done) { if (!$done) {
sleep(3); sleep(3);
} }
return new JsonResponse(compact('done', 'msg', 'data'), $done ? 200 : 401, $headers); return new JsonResponse(compact('done', 'msg', 'data'), $done ? 200 : 401);
}
/*!
* @method getResponseHeaders
* @private
* @param [assoc] $headers
* @return [assoc]
*/
private function getResponseHeaders($headers=[], $tokenResponse=null)
{
if (!empty($tokenResponse) || !empty($tokenResponse = $this->session->get('pwsauth.response'))) {
$headers['Pws-Response'] = $tokenResponse;
}
return $headers;
} }
/*! /*!
@ -165,20 +149,18 @@ class Authentication
if (!$this->isAllowedRoute($request->getPathInfo())) { if (!$this->isAllowedRoute($request->getPathInfo())) {
$done = false; $done = false;
$msg = "authentication require"; $msg = "authentication require";
$headers = [];
try { try {
$token = $this->authenticator->getToken(); $token = $this->authenticator->getToken();
$tokenResponse = $this->authenticator->generateResponseHeader($token);
$headers = $this->getResponseHeaders($headers, $tokenResponse);
if ($this->authenticator->isValid($token)) { if ($this->authenticator->isValid($token)) {
if (!empty($sid = $this->authenticator->getSessionId($token))) { if (!empty($sid = $this->authenticator->getSessionId($token))) {
$this->sessionInvalidate(); $this->sessionInvalidate();
$this->session->setId($sid); $this->session->setId($sid);
$this->session->start(); $this->session->start();
$user = $this->session->get('user'); $user = $this->session->get('user');
$data = compact('user');
// done : lets controller takes hand // done : lets controller takes hand
if (!is_null($user) && $user->key == $token->getIdent()) { if (!is_null($user) && $user->key == $token->getIdent()) {
$this->session->set('pwsauth.response', $tokenResponse);
return; return;
} }
else { else {
@ -191,7 +173,7 @@ class Authentication
$done = false; $done = false;
$msg = $e->getMessage(); $msg = $e->getMessage();
} }
return new JsonResponse(compact('done', 'msg', 'data'), 401, $headers); return new JsonResponse(compact('done', 'msg', 'data'), 401);
} }
} }
} }

View File

@ -49,16 +49,12 @@ class Controller extends Base
* @param [] $data * @param [] $data
* @return Symfony\Component\HttpFoundation\JsonResponse * @return Symfony\Component\HttpFoundation\JsonResponse
*/ */
public function response($done = false, $msg = "fail", $data = null, $tokenResponse = null) public function response($done = false, $msg = "fail", $data = null)
{ {
if (is_null($data)) { if (is_null($data)) {
unset($data); unset($data);
} }
$headers = []; $response = new JsonResponse(compact('done', 'msg', 'data'), 200);
if (!empty($tokenResponse) || !empty($tokenResponse = $this->session->get('pwsauth.response'))) {
$headers['Pws-Response'] = $tokenResponse;
}
$response = new JsonResponse(compact('done', 'msg', 'data'), 200, $headers);
return $response; return $response;
} }
@ -107,12 +103,11 @@ class Controller extends Base
*/ */
public function logout() public function logout()
{ {
$tokenResponse = $this->session->isStarted() ? $this->session->get('pwsauth.response') : null;
$this->handler->sessionInvalidate(); $this->handler->sessionInvalidate();
$sessid = $this->session->getId(); $sessid = $this->session->getId();
$done = true; $done = true;
$msg = 'session logout'; $msg = 'session logout';
return $this->response($done, $msg, null, $tokenResponse); return $this->response($done, $msg);
} }
/*! /*!