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

hook for modifying XHR before JSON feed request #4627

Open
azuken opened this issue Apr 10, 2019 · 14 comments
Open

hook for modifying XHR before JSON feed request #4627

azuken opened this issue Apr 10, 2019 · 14 comments
Labels
Accepted Event Fetching How event data is fetched

Comments

@azuken
Copy link

azuken commented Apr 10, 2019

Hello,

I'm trying today to migrate my company's app from v3 to v4, and I'm facing a problem with eventSources component. In v3, we used beforeSend function to get http request, and set Authorization header (for bearer token).

Now in v4, it does not call beforeSend function, and does not use headers params. I didn't find any doc or code from the internet with a solution.

Is it just not implemented ?

We've search in source and found nothing about it too.

What I tried :

(v3 base code)

beforeSend: function (xhr) {
    xhr.setRequestHeader('Authorization', 'Bearer ' + token);
},

(v4)

headers: { 'Authorization': 'Bearer ' + token }
headers: { Authorization: 'Bearer ' + token }

Thanks in advance !

@acerix
Copy link
Member

acerix commented Apr 12, 2019

You could supply the events as a function which gives you more control: https://fullcalendar.io/docs/events-function

I believe it's not possible with "events as JSON" currently but we could look at adding that support if you are requesting that feature.

@azuken
Copy link
Author

azuken commented Apr 15, 2019

Ok thanks for the link, I will look at it later. For the feature request, is there any procedure to do it ?

@acerix acerix changed the title How to set Authorization header in eventSources HTTP request Ability to set Authorization header in eventSources for JSON event source Apr 15, 2019
@acerix
Copy link
Member

acerix commented Apr 15, 2019

This issue can be the "feature request" but we don't have an ETA for adding new features. This page has the details:

https://fullcalendar.io/requesting-features

@arshaw
Copy link
Member

arshaw commented Apr 22, 2019

in v4, we should offer a hook to manipulate the XHR before it requests. keeping this ticket open for this feature request

@arshaw arshaw changed the title Ability to set Authorization header in eventSources for JSON event source hook for modifying XHR before JSON feed request Apr 22, 2019
@arshaw arshaw added Event Fetching How event data is fetched and removed Event Source labels Jul 30, 2019
@MiguelFaria
Copy link

hi @arshaw,

thare is any forecast about when this feature is gona be released ??

@markoangelovski
Copy link

Dear @arshaw and team,

In addition to OP's note about setting the Authorization header, may I kindly add that it would be great if the provision was available for setting the xhr.withCredentials = true.

My project is using it for authorization purposes, and currently there is no way for setting this option without modifying the source.

Thank you.

@m8iog
Copy link

m8iog commented Feb 13, 2020

I don't know if you've solved your problem @azuken, but I found a solution in the event source as a function.

                events: function (info, successCallback, failureCallback) {
                    let start = moment(info.start.valueOf()).format('YYYY-MM-DD');
                    let end = moment(info.end.valueOf()).format('YYYY-MM-DD');
                    $.ajax({
                        url: "api/assignments/?event_id=" + vm.eventId +  '&start='+ start + "&end=" + end,
                        type: 'GET',
                        headers: {
                            'X-CSRF-TOKEN': window.csrf_token
                        }, success: function (response) {
                                successCallback(response);
                        }
                    });
                },

I also used the same approach for the resources, which works for me. It's not the most elegant way, but it gets the job done.

Anyhow, just thought I'd share my solution.

@azuken
Copy link
Author

azuken commented Feb 14, 2020

This is exactly how I figured out to solve my problem !

@vinayverghese
Copy link

I don't know if you've solved your problem @azuken, but I found a solution in the event source as a function.

                events: function (info, successCallback, failureCallback) {
                    let start = moment(info.start.valueOf()).format('YYYY-MM-DD');
                    let end = moment(info.end.valueOf()).format('YYYY-MM-DD');
                    $.ajax({
                        url: "api/assignments/?event_id=" + vm.eventId +  '&start='+ start + "&end=" + end,
                        type: 'GET',
                        headers: {
                            'X-CSRF-TOKEN': window.csrf_token
                        }, success: function (response) {
                                successCallback(response);
                        }
                    });
                },

I also used the same approach for the resources, which works for me. It's not the most elegant way, but it gets the job done.

Anyhow, just thought I'd share my solution.

Thank you. I just had to tweak it for TypeScript in my case and it worked.

@oldmansutton
Copy link

Chiming in to say that being able to pass headers in the events object is essential as the world is using JWT for auth more and more.

@Luis85
Copy link

Luis85 commented Jun 7, 2021

Chiming in to say that being able to pass headers in the events object is essential as the world is using JWT for auth more and more.

I second this, trying to use the json source even with an X-API-KEY is not possible.

Are there any plans to add header params in the near future?

@uflidd
Copy link

uflidd commented Jun 30, 2021

I second this.

Attempting to make @m8iog's solution to work in the meantime

I don't know if you've solved your problem @azuken, but I found a solution in the event source as a function.

                events: function (info, successCallback, failureCallback) {
                    let start = moment(info.start.valueOf()).format('YYYY-MM-DD');
                    let end = moment(info.end.valueOf()).format('YYYY-MM-DD');
                    $.ajax({
                        url: "api/assignments/?event_id=" + vm.eventId +  '&start='+ start + "&end=" + end,
                        type: 'GET',
                        headers: {
                            'X-CSRF-TOKEN': window.csrf_token
                        }, success: function (response) {
                                successCallback(response);
                        }
                    });
                },

I also used the same approach for the resources, which works for me. It's not the most elegant way, but it gets the job done.

Anyhow, just thought I'd share my solution.

@jdhorner
Copy link

I don't want to add noise, but I hope I do add a voice: I'm upgrading my company's (pro-licensed) version of Full Calendar from version 3 to version 5, and among the many frustrating changes, the ability to simply specify a "headers" object on the eventSource being removed is very challenging. I now have to rewrite the entire thing as an event function using my ajax library just for the same purpose. So consider this a vote for hoping to be able to add headers to JSON event feeds ASAP. 💙

@dave1quovadimus
Copy link

m8iog; Thank you for the code example. I'm new to FullCalendar, all was going great, but I need to include a nonce, in the header. This could have been a show stopper for me. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Event Fetching How event data is fetched
Projects
Status: No status
Development

No branches or pull requests