-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fix CORS with cookies #576
Comments
Before changing this, we should think about how other services would interact with JabRefOnline in the first place and consider options like OAuth. Then for now a quick-fix would be to have a special handling for calls from "localhost" when the server is in development mode. |
I think OAuth uses tokens for auth.
I've tried enabling the cors for localhost:3000 with the credentials set to true. I've also tried to change the cookie setting to make it work with cross-origin ( samesite=none, secure = true). But it didn't work. Cors: I came across this article: https://docs.microsoft.com/en-us/office/dev/add-ins/develop/itp-and-third-party-cookies. According to this article, "When developing Office Add-ins on Mac, access to third-party cookies is blocked by the macOS Big Sur SDK. This is because WKWebView ITP is enabled by default on the Safari browser, and WKWebView blocks all third-party cookies. Office on Mac version 16.44 or later is integrated with the macOS Big Sur SDK." This could be an issue related MacOs, so could you please try on windows? And I think word online use iframe, and iframe does not store third-party cookies. So the only option we are left with is to run both addin and jabref on the same origin. Which is pretty complex, but I think we can set up a reverse proxy with Nginx and that is what I'm currently trying. |
Oh man, turned out I had to read quite a bit to catch up with the recommended auth strategies. First of all, OAuth2 is indeed the recommended standard. In particular the "device code" flow may be helpful for auth with JabRef Desktop since then people don't need to enter their auths in the desktop app. I'll open a new issue for the OAuth stuff. But for the word addin this is not helpful at all for the following reason. Oauth's process looks as follows:
So in this case you need a very slim backend (often called backend-for-frontend) that does the exchange grant > access token. To advantage is that the access token is never stored in plain text on the users side. Otherwise you would need to store it say in localStorage or something, which can be exploited. This leaves us with the option of a) creating such a slim backend for the office addin or b) add a reverse proxy to put the office add-in on the same domain as the jabref online api. The first option is overkill in my opinion and the second looked like a lot of work. But it turns out that we don't need to worry about this at all since Azure provides a nice workaround. When you setup a Static Web app, you can link it with an existing Azure Functions instance and azure will provide an automatic proxy from say
where the api-location is the running azure functions instance (i.e. jabref online api), see https://docs.microsoft.com/en-us/azure/static-web-apps/local-development. So as a path forward I propose:
@mohit038 What do you think? |
After reading a bit more, I came up with the following model:
|
Some progress is in #1242, but it currently doesn't work on Azure due to Azure/static-web-apps#108? or Azure/static-web-apps#588. Probably can be fixed via using a bring-your-own function app #1343. Similar issue:
|
The first part of #576 (comment) is now implemented: The main website is a static web app that is connected to a bring-your-own-function-app. Linking to the office website is still missing, but let's track this in the office add-in repo. Moreover, let's see if there is indeed need for an |
As reported by @mohit038, it is currently not possible to authenticate with the API via a cross-origin request. The session cookie is included in the response from the API but then is ignored by the browser (i.e. not sent back in the next request).
Most likely, the problem is that we have
Access-Control-Allow-Origin: *
which doesn't work with credentials as described here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin. In this document, the recommend to take theOrigin
of the callee as the allowed origin. See also https://stackoverflow.com/questions/46288437/set-cookies-for-cross-origin-requests.And finally there might be issues during development as
localhost
may need special handling: https://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain/1188145#1188145@mohit038 You said you already tried a lot of different stuff to make this work. Can you shortly comment on if you tried also explicitly setting the "Allow-Origin" option, and if that didn't worked what else you tried in this combination.
The text was updated successfully, but these errors were encountered: