decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.96k stars 3.05k forks source link

Login with github as backend fails if base url contains additional path segment #3622

Open agairing opened 4 years ago

agairing commented 4 years ago

Describe the bug If you use github as backend the following basic setup is required:

Example:

The authentication and token creation with github is successfull but the communication between the auth popup and the original page fails.

To Reproduce

Expected behavior Login should work

Applicable Versions:

Additional context It seems that the following check in netlify-auth.js is not working: e.origin !== this.base_url I think origin is always just the host without any path segment.

erezrokah commented 4 years ago

Thanks @agairing, looks like origin contains the schema and port too: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#The_dispatched_event We would gladly accept a PR for it (probably we just need to parse base_url and reconstruct without the path).

agairing commented 4 years ago

Ok, and I can try to create a PR. What about sth. like this.base_url.indexOf(e.origin) !== 0 ?

erezrokah commented 4 years ago

How about e.origin !== new URL(this.base_url).origin ? It makes it clear what we're checking and is stricter.

agairing commented 4 years ago

Fine for me. I just did the local setup and executed the tests before changing anything. 34 tests are failing on windows. Example: Expected: ObjectContaining {"path": "static/media/abc_def_eaco_.png"} Received: {"field": undefined, "fileObj": {}, "path": "static\\media\\abc_def_eaco_.png", "url": "displayURL"}

How should this be handled? At first glance, it seems that the test is not cross platform compatible.

erezrokah commented 4 years ago

@agairing, thanks for letting us know. I opened an new issue for that https://github.com/netlify/netlify-cms/issues/3655 and I'm surprised our CI doesn't fail it since it we run the tests on Widows too: https://github.com/netlify/netlify-cms/runs/609296943?check_suite_focus=true#step:6:1496. I think you could just test the fix locally and submit it and I'll take care of the tests.

peace-for-all commented 2 years ago

I'm sorry, if wrong place to ask, but:

https://www.netlifycms.org/docs/backends-overview/#backend-configuration From my understanding of this doc, the case described in original post should be configured as

base_url: https://mygithub-auth-backend.org/oauth2
auth_endpoint: oauth2

Is this right or am I misreading the doc? Thanks. :-)

aaron2198 commented 1 year ago

After a few days of fighting with it @walxin I think we both misread the doc as it states "OAuth client hostname (just the base domain, no path)" for base_url, like https://mygithub-auth-backend.org. Then auth_endpoint would be the full path to your specific auth destination, like oauth2. For us this was, oauth/auth, We were trying to tuck all auth endpoints behind a prefix (oauth) to play nicely with a cluttered domain and got really hung up with this. I don't suspect a PR is required to solve this issue, it was possible to manage without changing how the code works. It is even written clearly, I suppose sometimes these things are just hard to interpret.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.