Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withStatus(401) in __invoke call #110

Closed
doveraldo opened this issue Mar 30, 2018 · 6 comments
Closed

withStatus(401) in __invoke call #110

doveraldo opened this issue Mar 30, 2018 · 6 comments

Comments

@doveraldo
Copy link

when token cannot be found or decoded or false is returned on callback the response code is forced to be 401 after calling the error function.

this gives the app no chance to redirect etc.
Be nice if withStatus(401) is called before the error function, giving it the option to override it

@tuupola
Copy link
Owner

tuupola commented Mar 30, 2018

The 3.x branch should not have this problem anymore.

@doveraldo
Copy link
Author

doveraldo commented Mar 30, 2018 via email

@tuupola
Copy link
Owner

tuupola commented Mar 30, 2018

Hmmh. Good point about PHP versions. I need to think a bit if changing this behavior is a BC break. I think it should be ok.

@doveraldo
Copy link
Author

doveraldo commented Mar 30, 2018

changes I propose....this works for me. I would do a pull request...but ...maybe tomorrow.

    /* If token cannot be found return with 401 Unauthorized. */
    if (false === $token = $this->fetchToken($request)) {
        return $this->error($request, $response->**withStatus(401)**, [
            "message" => $this->message
        ]);
    }

    /* If token cannot be decoded return with 401 Unauthorized. */
    if (false === $decoded = $this->decodeToken($token)) {
        return $this->error($request, $response->**withStatus(401)**, [
            "message" => $this->message,
            "token" => $token
        ]);
    }

    /* If callback returns false return with 401 Unauthorized. */
    if (is_callable($this->options["callback"])) {
        $params = ["decoded" => $decoded];
        if (false === $this->options["callback"]($request, $response, $params)) {
            return $this->error($request, $response->**withStatus(401)**, [
                "message" => $this->message ? $this->message : "Callback returned false"
            ]);
        }
    }

@doveraldo
Copy link
Author

PR made #111

@tuupola
Copy link
Owner

tuupola commented Apr 3, 2018

Merged e6de664. Released as 2.4.0.

@tuupola tuupola closed this as completed Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants