Skip to content

Commit eb83a27

Browse files
committed
fix onUnAuthorized error
1 parent 8766630 commit eb83a27

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Phalcon/Auth/Middleware/Micro.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,22 @@ public function onUnauthorized(callable $callback)
272272
*/
273273
public function unauthorized() {
274274
if($this->_onUnauthorized) {
275-
return $this->_onUnauthorized($this, $this->app);
275+
return call_user_func($this->_onUnauthorized, $this, $this->app);
276276
}
277277

278278
$response = $this->app["response"];
279279
$response->setStatusCode(401, 'Unauthorized');
280280
$response->setContentType("application/json");
281281
$response->setContent(json_encode([$this->getMessages()[0]]));
282+
283+
// CORS
284+
if($this->isIgnoreOptionsMethod()) {
285+
$response->setHeader("Access-Control-Allow-Origin", '*')
286+
->setHeader("Access-Control-Allow-Methods", 'GET,PUT,POST,DELETE,OPTIONS')
287+
->setHeader("Access-Control-Allow-Headers", 'Origin, X-Requested-With, Content-Range, Content-Disposition, Content-Type, Authorization')
288+
->setHeader("Access-Control-Allow-Credentials", true);
289+
}
290+
282291
$response->send();
283292
return false;
284293
}

0 commit comments

Comments
 (0)