wp-graphql-jwt-authentication icon indicating copy to clipboard operation
wp-graphql-jwt-authentication copied to clipboard

Internal server error

Open homerjam opened this issue 5 years ago • 19 comments

Following the steps in the video tutorial in the README (adding Authorisation header with bearer token) I get the following:

query MyQuery {
  viewer {
    id
  }
}
{
    "errors": [
        {
            "message": "Internal server error",
            "category": "internal",
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ],
            "path": [
                "viewer"
            ]
        }
    ],
    "data": {
        "viewer": null
    }
}

I'm not sure how to begin debugging this??

I'm using the latest versions of wp-graphql and wp-graphql-jwt-authentication.

Thanks, James

homerjam avatar Jan 14 '20 15:01 homerjam

@homerjam first thing to try is add define( 'GRAPHQL_DEBUG', true ); to your WordPress wp-config.php file. That will give you more explicit errors. Many times errors are masked as Internal Server Error for public users as they might leak sensitive implementation details.

Can you post the error you're seeing once you define GRAPHQL_DEBUG?

jasonbahl avatar Jan 14 '20 15:01 jasonbahl

Thanks Jason.

That gives the following:

{
"errors": [
{
"debugMessage": "You must be logged in to access viewer fields",
"message": "Internal server error",
"category": "internal",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"viewer"
]
}
],
"data": {
"viewer": null
}
}
curl --location --request POST 'http://localhost:8080/index.php?graphql'; \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbWFtYWdzdHVkaW9zLmNvbSIsImlhdCI6MTU3OTAxNjY0NCwibmJmIjoxNTc5MDE2NjQ0LCJleHAiOjE1NzkwMTY5NDQsImRhdGEiOnsidXNlciI6eyJpZCI6IjEifX19.CDMjzmLK-TO9tLpjk39TTVfbG0_LERdrWQxaZn397ZM' \
--data-raw '{"query":"query MyQuery {\n viewer {\n id\n }\n}\n","variables":{}}'

On 14 Jan 2020, 15:27 +0000, Jason Bahl [email protected], wrote:

@homerjam first thing to try is add define( 'GRAPHQL_DEBUG', true ); to your WordPress wp-config.php file. That will give you more explicit errors. Many times errors are masked as Internal Server Error for public users as they might leak sensitive implementation details. Can you post the error you're seeing once you define GRAPHQL_DEBUG? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

homerjam avatar Jan 14 '20 15:01 homerjam

@homerjam was that a fresh token? The authToken has a 5-minute expiration and needs to be refreshed regularly.

In the response headers for every authenticated request is another authToken, so you can use that to add another 5-minutes by replacing your existing authToken with the new one.

If it expires, you can use the refreshToken to get a new authToken.

If you don't think this is an expired token, there's a chance your server setup (nginx/apache) may need configured to allow Authorization headers to be passed through.

jasonbahl avatar Jan 14 '20 16:01 jasonbahl

Yep, that one was fresh and I've just tried again to double check.

The Authorization header is getting through - I've verified using PHP's getallheaders.

Screenshot 2020-01-14 16 28 17

homerjam avatar Jan 14 '20 16:01 homerjam

@homerjam I wonder if it's because the token is coming from a different domain? 🤔

I'm seeing the token was issued by https://mamagstudios.com but according to your post you're trying to use it on http://localhost:8080

jasonbahl avatar Jan 14 '20 16:01 jasonbahl

Ah yes, it's a headless setup so the domains are different ie. in WP_HOME and WP_SITEURL

homerjam avatar Jan 14 '20 16:01 homerjam

@homerjam ah. This might be a bug then in WPGraphQL JWT Auth plugin. 🤔

jasonbahl avatar Jan 14 '20 16:01 jasonbahl

Try changing this line to site_url() https://github.com/wp-graphql/wp-graphql-jwt-authentication/blob/master/src/Auth.php#L150

jasonbahl avatar Jan 14 '20 16:01 jasonbahl

good catch! I think it's a very common case for folks to have WP_HOME and WP_SITEURL different, and I don't think I've tested that scenario enough. Most of the projects I was working on were on completely different domains so these issues weren't apparent for me.

jasonbahl avatar Jan 14 '20 16:01 jasonbahl

Hmm. Sadly no joy. I also tried changing the other iss check on line 565.

homerjam avatar Jan 14 '20 16:01 homerjam

Did you login and get new tokens after making that change?

jasonbahl avatar Jan 14 '20 17:01 jasonbahl

Yeah, ran the login mutation right?

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODA4MCIsImlhdCI6MTU3OTAyMTM1NCwibmJmIjoxNTc5MDIxMzU0LCJleHAiOjE1NzkwMjE2NTQsImRhdGEiOnsidXNlciI6eyJpZCI6IjEifX19.lqefacDwk_8b4f4Lxnk6b8-pDzamZBG0thFB7otNmpI

homerjam avatar Jan 14 '20 17:01 homerjam

Ok, I do see the issuer is now http://localhost:8080. Let me check some things. Give me a few moments.

Also would be happy to hop on a zoom / Google Hangout and work through this together

jasonbahl avatar Jan 14 '20 17:01 jasonbahl

try using 127.0.0.1 instead of localhost, had the same issue I believe.

flowoow avatar Jan 25 '20 15:01 flowoow

I'm getting the same result here with the message "You must be logged in to access viewer fields", strange because the X-JWT-Auth and X-JWT-Refresh are coming back.

-Edit- narrowed it down to a plugin conflict, if anyone else perhaps runs GiveWP, the donation plugin, line wp-content/plugins/give/includes/class-give-session.php:186 is somehow causing this issue. It seems that they add this filter if the user is not logged in, and even though this plugin for JWT auth adds a filter to determine_current_user in WordPress, it doesn't resolve the current user anyways from the authentication headers in time.

saleebm avatar Feb 04 '20 22:02 saleebm

I had the same issue until I deactivated plugins "The Events Calendar" and "Event Tickets".

robertvorthman avatar Mar 21 '20 05:03 robertvorthman

I moved define( 'GRAPHQL_JWT_AUTH_SECRET_KEY', '.....') from the bottom of my theme's functions.php to wp-config.php and now the error is gone even though I've reenabled both "The Events Calendar" and "Event Tickets".

robertvorthman avatar Mar 21 '20 06:03 robertvorthman

Did this get resolved at any point? I'm struggling with the same issue on a page and setting the iss to site_url() didn't work sadly. The token got the correct iss (same as the back-end) but it still throws an error: invalid-jwt | The iss do not match with this server.

Mikethekidmyers avatar Oct 16 '20 15:10 Mikethekidmyers

Screenshot (61)

Help with this issue "No session Found" while using mutation

TheSolamipe avatar May 27 '21 00:05 TheSolamipe