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

[Bug] /admin/admin-ajax.php blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. #7

Open
abdennour opened this issue Jul 31, 2021 · 2 comments

Comments

@abdennour
Copy link

abdennour commented Jul 31, 2021

Overview

I setup the plugin with keycloak & everything is going well (login, logout,...) ,
However... except when clicking on the button which generates new shorten link :

I am getting this error on the browser console:

https://yourls.company.com/admin/?state=d27b8870a0a2301dc6ad72c373d89239&session_state=blah-blah-blah&code=BLAHBLAH

Access to XMLHttpRequest at
 'https://keycloak.company.com/auth/realms/myrealm/protocol/openid-connect/auth?response_type=code&redirect_uri=http%3A%2F%2Fyourls.company.com%2Fadmin%2Fadmin-ajax.php&client_id=yourls&nonce=ec2c2.........&state=9ab......&scope=openid' 
 (redirected from 'https://yourls.company.com/admin/admin-ajax.php?action=add&url=https%3A%2F%2FLONG-URL-THAT-IWANT-TO-SHORTEN&keyword=&nonce=8489da0f63') from origin 'https://yourls.company.com' has been blocked by CORS policy: 
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

steps to reproduce :

  1. Run yourls v1.8.1

  2. Installing the following plugins :

  3. Deploy everything thru the official helm chart

  4. Configure keycloak as following:
    image

Expected Behavior

I would expect that all actions should be authenticated with keycloak without bugs and errors.

Actual Behavior

Actually, the API responsible for generating the shorten link (Which is the main functionality) is not working and it's thrown CORS issue

Attempts to fix :

Unfortunately, it does not work, and i am still getting the same issue.

Tips :

@joshp23
Copy link
Owner

joshp23 commented Dec 28, 2021

Your issue seems to provide the answer here

No 'Access-Control-Allow-Origin' header is present on the requested resource.

So adding something like the following to your vhost config should do the trick:

Access-Control-Allow-Origin: *

or maybe something a bit more specific like the following

Access-Control-Allow-Origin: https://example.com

@fservida
Copy link

fservida commented May 1, 2022

I'm having the same issue, I think it might be related to yourls / the plugin not respecting the session cookie after authentication and trying to reauthenticate the XHR requests against the openid provider.

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

No branches or pull requests

3 participants