49 public function __invoke($request, $response, $next)
51 $requestUri = $request->getUri();
52 if (stristr($requestUri->getPath(),
"/auth") !==
false) {
53 $response = $next($request, $response);
54 } elseif (stristr($requestUri->getPath(),
"/version") !==
false) {
55 $response = $next($request, $response);
56 } elseif (stristr($requestUri->getPath(),
"/tokens") !==
false &&
57 stristr($request->getMethod(),
"post") !==
false) {
58 $response = $next($request, $response);
60 $authHelper = $GLOBALS[
'container']->get(
'helper.authHelper');
61 $jwtToken = $request->getHeader(
'Authorization')[0];
64 $tokenValid = $authHelper->verifyAuthToken($jwtToken, $userId,
66 if ($tokenValid ===
true && (stristr($request->getMethod(),
"get") ===
false &&
67 stristr($tokenScope,
"write") ===
false)) {
72 $tokenValid =
new Info(403,
"Do not have required scope.", InfoType::ERROR);
74 if ($tokenValid ===
true) {
76 $groupName = strval($request->getHeaderLine(
'groupName'));
77 if (!empty($groupName)) {
78 $userHasGroupAccess = $authHelper->userHasGroupAccess($userId, $groupName);
79 if ($userHasGroupAccess ===
true) {
80 $authHelper->updateUserSession($userId, $tokenScope, $groupName);
81 $response = $next($request, $response);
83 $response = $response->withJson($userHasGroupAccess->getArray(),
84 $userHasGroupAccess->getCode());
87 $authHelper->updateUserSession($userId, $tokenScope);
88 $response = $next($request, $response);
91 $response = $response->withJson($tokenValid->getArray(),
92 $tokenValid->getCode());
__invoke($request, $response, $next)
Info model to contain general error and return values.
Authentication middleware for Slim framework.