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": {
"php" : "^7.0",
"meta-tech/pws-auth" : "@dev",
"meta-tech/pws-auth" : "^2.1",
"meta-tech/silex-controller-service" : "^1.0",
"silex/silex": "^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
* @public

View File

@ -98,10 +98,8 @@ class Authentication
$done = false;
$msg = 'authentication require';
$token = $this->authenticator->getToken();
$login = $request->get('login');
$responseToken = $this->authenticator->generateResponseHeader($token);
$headers = $this->getResponseHeaders([], $responseToken);
if ($this->authenticator->isValid($token)) {
$login = $request->get('login');
$password = $request->get('password');
if ($this->authenticator->check($token, $login)) {
try {
@ -119,21 +117,7 @@ class Authentication
if (!$done) {
sleep(3);
}
return new JsonResponse(compact('done', 'msg', 'data'), $done ? 200 : 401, $headers);
}
/*!
* @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;
return new JsonResponse(compact('done', 'msg', 'data'), $done ? 200 : 401);
}
/*!
@ -165,20 +149,18 @@ class Authentication
if (!$this->isAllowedRoute($request->getPathInfo())) {
$done = false;
$msg = "authentication require";
$headers = [];
try {
$token = $this->authenticator->getToken();
$tokenResponse = $this->authenticator->generateResponseHeader($token);
$headers = $this->getResponseHeaders($headers, $tokenResponse);
if ($this->authenticator->isValid($token)) {
if (!empty($sid = $this->authenticator->getSessionId($token))) {
$this->sessionInvalidate();
$this->session->setId($sid);
$this->session->start();
$user = $this->session->get('user');
$data = compact('user');
// done : lets controller takes hand
if (!is_null($user) && $user->key == $token->getIdent()) {
$this->session->set('pwsauth.response', $tokenResponse);
return;
}
else {
@ -191,7 +173,7 @@ class Authentication
$done = false;
$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
* @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)) {
unset($data);
}
$headers = [];
if (!empty($tokenResponse) || !empty($tokenResponse = $this->session->get('pwsauth.response'))) {
$headers['Pws-Response'] = $tokenResponse;
}
$response = new JsonResponse(compact('done', 'msg', 'data'), 200, $headers);
$response = new JsonResponse(compact('done', 'msg', 'data'), 200);
return $response;
}
@ -107,12 +103,11 @@ class Controller extends Base
*/
public function logout()
{
$tokenResponse = $this->session->isStarted() ? $this->session->get('pwsauth.response') : null;
$this->handler->sessionInvalidate();
$sessid = $this->session->getId();
$done = true;
$msg = 'session logout';
return $this->response($done, $msg, null, $tokenResponse);
return $this->response($done, $msg);
}
/*!