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

Guard issue in production only #144

Closed
newtoniumx3 opened this issue Mar 12, 2021 · 2 comments
Closed

Guard issue in production only #144

newtoniumx3 opened this issue Mar 12, 2021 · 2 comments
Labels
question Further information is requested

Comments

@newtoniumx3
Copy link

I'm having such a strange issue I don't understand what could be wrong.
My code/configuration locally is not behaving the same way in production.

The workflow

  1. Send a login request and receive back an access_token
  2. Send a second request with the access_token in the header as: Authorization: Bearer ...

enter image description here

In production

  1. Step 1 works I receive back the access_token.
  2. Step 2, I always get back a null user session. I checked in production and the Authorization header does arrive intact and the value is also correct. But then why would it not process this properly like in localhost?

Specifically my issue is here:
src/server/vendor/nuwave/lighthouse/src/Support/Http/Middleware/AttemptAuthentication.php

protected function attemptAuthentication(array $guards): void
{
    if (empty($guards)) {
        $guards = [config('lighthouse.guard')];
    }

    foreach ($guards as $guard) {
        if ($this->authFactory->guard($guard)->check()) { // <---- the culprint
            $this->authFactory->shouldUse($guard);

            return;
        }
    }
}

On both development and production guards has the same value of ['api'].
However in development the following line returns true, but in production this returns false

$this->authFactory->guard($guard)->check()

How could this be? It's the exact same code running.

I specifically validated on production that the token I'm sending does not get altered and is properly received. It is the token specifically returned by the login endpoint of production.


@joselfonseca
Copy link
Owner

@newtoniumx3 Make sure your web server is passing along the Authorization header, some servers are not configure to allow that header to be passed on the request so the header will never get there to be validated.

@joselfonseca joselfonseca added the question Further information is requested label Mar 17, 2021
@newtoniumx3
Copy link
Author

I’m going to re setup my app from scratch to debug this. If the issue still happens I’ll re open this. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants