Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Laravel Passport Support? #8

Open
tankerkiller125 opened this issue Feb 27, 2018 · 1 comment
Open

Laravel Passport Support? #8

tankerkiller125 opened this issue Feb 27, 2018 · 1 comment

Comments

@tankerkiller125
Copy link

tankerkiller125 commented Feb 27, 2018

It seems that if I enable Laravel passport on my graphql endpoint I can not get GraphiQL to work, even if I add the 'X-Requested-With' => 'XMLHttpRequest' header to the request it uses. Based on my research I found that it is not sending the X-CSRF-TOKEN or the 'X-XSRF-TOKEN' which all other javascript based queries do when working with passport.

And it is also missing the laravel_token cookie as well.

Is their any fix for this?

@tankerkiller125
Copy link
Author

Update for anyone who has this issue in the future:

In the graphiql.php config add: 'X-Requested-With' => 'XMLHttpRequest', to the headers array.

Then in the resources/views/vendors/graphiql/index.blade.php section add 'X-CSRF-TOKEN': '{{ csrf_token() }}', to the fetch function after the @endforelse

The function should look something like:

function graphQLFetcher(graphQLParams) {
        //return fetch("http://localhost:8000/graphql", {
        return fetch("{{url(config('graphiql.routes.graphql'))}}", {
            method: 'post',
            headers: {
                @forelse(config('graphiql.headers') as $key => $value)
                '{{ $key }}': '{{ $value }}',
                @empty
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                @endforelse
                'X-CSRF-TOKEN': '{{ csrf_token() }}',
            },
            body: JSON.stringify(graphQLParams),
            credentials: 'same-origin',
        }).then(function (response) {
            return response.text();
        }).then(function (responseBody) {
            try {
                return JSON.parse(responseBody);
            } catch (error) {
                return responseBody;
            }
        });
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant