I just want to get this straight.
I’m using oauth2 to authenticate my client-side app (i.e. browser app) agains to google calendar v3 API. Until now I used a string parameter with the access_token to call the endpoints.
After I switched to header authentification I noticed that the browser needs two xhr requests to call an endpoint where the first one is OPTIONS and the second the actual GET request. This is an expected behavior, right?
Of course, under certain conditions this slows down the user experience. Is it possible to have only one xhr (GET) request with header authentification?
No. When setting a custom header (in this case an auth header) a preflight request is triggered. (Specs, Blogpost by Remy Sharp)
If you want to save the extra roundtrip call the endpoint with the
access_tokenparameter.If you still see a
OPTIONrequest, check if your js lib/framework sets a custom header. There was a (long gone) bug in jQuery for instance.