Closed Fshamri closed 7 years ago
Have you tried removing that line?
I have commented it but get
"title": "Authentication failed", "type": "about:blank", "status": 401
Show example curl request you are trying to do. That message tells the authentication failed, ie you are sending wrong credentials or not credentials at all.
curl "http://mobilepul.com/api/public/token" --request POST --include --header "Content-Type: application/json" --user test:test
Have you configured basic auth to the route /api/public/token
with credentials test
and test
?
this is from my middleware
use App\Token;
use Crell\ApiProblem\ApiProblem;
use Gofabian\Negotiation\NegotiationMiddleware;
use Micheh\Cache\CacheUtil;
use Slim\Middleware\JwtAuthentication;
use Slim\Middleware\HttpBasicAuthentication;
use Tuupola\Middleware\Cors;
$container = $app->getContainer();
$container["HttpBasicAuthentication"] = function ($container) {
return new HttpBasicAuthentication([
"path" => "/token",
"secure" => false,
"relaxed" => ["192.168.50.52"],
"error" => function ($request, $response, $arguments) {
$problem = new ApiProblem($arguments["message"], "about:blank");
$problem->setStatus(401);
return $response
->withHeader("Content-type", "application/problem+json")
->write($problem->asJson(true));
},
"users" => [
"test" => "test"
]
]);
};
$container["token"] = function ($container) {
return new Token;
};
$container["JwtAuthentication"] = function ($container) {
return new JwtAuthentication([
"path" => "/",
"secure" => false,
"passthrough" => ["/token", "/info"],
"secret" => getenv("JWT_SECRET"),
"logger" => $container["logger"],
"relaxed" => ["192.168.50.52"],
"error" => function ($request, $response, $arguments) {
$problem = new ApiProblem($arguments["message"], "about:blank");
$problem->setStatus(401);
return $response
->withHeader("Content-type", "application/problem+json")
->write($problem->asJson(true));
},
"callback" => function ($request, $response, $arguments) use ($container) {
$container["token"]->hydrate($arguments["decoded"]);
}
]);
};
$container["Cors"] = function ($container) {
return new Cors([
"logger" => $container["logger"],
"origin" => ["*"],
"methods" => ["GET", "POST", "PUT", "PATCH", "DELETE"],
"headers.allow" => ["Authorization", "If-Match", "If-Unmodified-Since"],
"headers.expose" => ["Authorization", "Etag"],
"credentials" => true,
"cache" => 60,
"error" => function ($request, $response, $arguments) {
$data["status"] = "error";
$data["message"] = $arguments["message"];
return $response
->withHeader("Content-Type", "application/json")
->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
]);
};
$container["Negotiation"] = function ($container) {
return new NegotiationMiddleware([
"accept" => ["application/json"]
]);
};
$app->add("HttpBasicAuthentication");
$app->add("JwtAuthentication");
$app->add("Cors");
$app->add("Negotiation");
$container["cache"] = function ($container) {
return new CacheUtil;
};
You have configured basic auth to path /token
but are requesting /api/public/token
. See Basic Auth middleware documentation on how to configure it.
if my curl is like: curl "http://mobilepul.com/token" --request POST --include --header "Content-Type: application/json" --user test:test
OR curl "http://mobilepul.com/api/token" i get 404 NOT FOUND.
i think .htaccess file needs some modification
here is my .htaccess file content: RewriteEngine On
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]
Things related to configuring Apache and Slim are better off asked in StackOverflow or Slim support forums. You probably have more luck finding answer there. GitHub issues are more meant for reporting bugs.
I am getting 500 internal server error. my host support is saying it is because of
what does -1 means? how to fix this issue?
Thanks