52 $warningMessage =
"The resource is deprecated. Use /tokens";
53 $returnVal =
new Info(406, $warningMessage, InfoType::ERROR);
55 return $response->withHeader(
'Warning', $warningMessage)->withJson(
56 $returnVal->getArray(), $returnVal->getCode());
69 $tokenRequestBody = $request->getParsedBody();
80 $error =
new Info(400,
81 "Following parameters are required in the request body: " .
82 join(
",", $paramsRequired), InfoType::ERROR);
83 $returnVal = $response->withJson($error->getArray(), $error->getCode());
85 $tokenValid = $this->restHelper->validateTokenRequest(
86 $tokenRequestBody[
"token_expire"], $tokenRequestBody[
"token_name"],
87 $tokenRequestBody[
"token_scope"]);
88 if ($tokenValid !==
true) {
89 $returnVal = $response->withJson($tokenValid->getArray(),
90 $tokenValid->getCode());
93 $authHelper = $this->restHelper->getAuthHelper();
94 if ($authHelper->checkUsernameAndPassword($tokenRequestBody[
"username"],
95 $tokenRequestBody[
"password"])) {
96 $userId = $this->restHelper->getUserId();
97 $expire = $tokenRequestBody[
"token_expire"];
98 $scope = $tokenRequestBody[
"token_scope"];
99 $name = $tokenRequestBody[
"token_name"];
103 $jti = $this->dbHelper->insertNewTokenKey($userId, $expire,
110 $jti = $this->dbHelper->insertNewTokenKey($userId, $expire,
114 $error =
new Info(429,
"Please try again later.", InfoType::ERROR);
115 $returnVal = $response->withHeader(
'Retry-After', 2)->withJson(
116 $error->getArray(), $error->getCode());
119 $error =
new Info($e->getCode(), $e->getMessage(), InfoType::ERROR);
120 $returnVal = $response->withJson($error->getArray(),
123 if (isset($jti[
'jti']) && ! empty($jti[
'jti'])) {
124 $theJwtToken = $this->restHelper->getAuthHelper()->generateJwtToken(
125 $expire, $jti[
'created_on'], $jti[
'jti'], $scope, $key);
126 $returnVal = $response->withJson([
127 "Authorization" =>
"Bearer " . $theJwtToken
131 $error =
new Info(404,
"Username or password incorrect.",
133 $returnVal = $response->withJson($error->getArray(), $error->getCode());
155 return !array_diff_key(array_flip($keys), $array);
Exception when a token has duplicate name for same user.
Base controller for REST calls.
arrayKeysExists($array, $keys)
Check if a list of keys exists in associative array.
createNewJwtToken($request, $response, $args)
Exception when a token has duplicate key for same user.
Controller for Auth requests.
getAuthHeaders($request, $response, $args)
Info model to contain general error and return values.