react-twitter-auth icon indicating copy to clipboard operation
react-twitter-auth copied to clipboard

Blocked a frame with origin ... from accessing a cross-origin frame.

Open josejaguirre opened this issue 6 years ago • 16 comments

Hello, I think the library is great for managing twitter login, but I have a problem, when I want to use the component to make the login, I get the following error Error: Blocked a frame with origin" http: // localhost: 3000 " from accessing to cross-origin frame. In my specific case I am using my localhost` to be able to use proof of concept, and I enabled the cors, but I can not make it work. Is there any indication on this? or I'm doing something wrong when using the library

josejaguirre avatar Nov 25 '17 06:11 josejaguirre

Hi,

This should be working. Also in example folder you can find an example with Node.js/Express.js application and React application. Both are hosted on localhost, but on two separate ports. Also i've created tutorial that explains similar setup.

You shouldn't have any issues.

ivanvs avatar Nov 25 '17 11:11 ivanvs

I currently manage a project in which everyone has work with their own server (backend and frontend), the part of the backend worked excellent for me, but when using the react component, I see that a window.open is created, to be able to open the twitter registration window, when entering the polling that window has problems with the cors permissions, so that part is the one that has stopped me, both on the backend server (api), as in the client enable the cors permission as you have it in the tutorial and I could not pass the setInterval cycle, some recommendation ?? , thanks for answering

josejaguirre avatar Nov 25 '17 15:11 josejaguirre

Sorry for late response, but you should not have any other configuration for cors in frontend. Pay attention that you have correctly set up cors on backend.

ivanvs avatar Dec 21 '17 12:12 ivanvs

Hello, I get the same issue, and my cors in the backend are correctly set... however the problem seems to come from the frontend that can not be able to get data from a popup without the same origine (like twitter.com). Did you found a workaround ?

Veldars avatar Feb 17 '18 17:02 Veldars

Hi @Veldars,

I haven't manage to reproduce this issue. Do you use latest version of library? What is the value for credentials prop that you are using?

I just need more information about the issue.

ivanvs avatar Feb 18 '18 23:02 ivanvs

Ok, thanks for your quick answer.

Yes I download the last version of the library. I tried with every possible value for credentials, but the error is still there. But for me I don't understant how it could work. I had read the code of your library and after some internet research, The parent window of a popup cannot access to anything from the popup if the origine of the popup is not the same that the parent window. So if you try to get data like popup.location.hostname the browser will throw an error if the origin is not the same. I haven't found any solution for this kind of problème. If you need it, here is my call of the TwitterLogin.

  <TwitterLogin loginUrl={`${Conf.BaseURL}auth/twitter`}
              onFailure={this.onFailed} onSuccess={this.onSuccess}
              requestTokenUrl={`${Conf.BaseURL}auth/twitter/reverse`}/>

I have removed the credential parameter because you do not use it in your examples.

Thanks

Veldars avatar Feb 19 '18 07:02 Veldars

I modified the component to use the callback offered by tweet, since it was impossible to obtain the token directly to authenticate

josejaguirre avatar Feb 19 '18 13:02 josejaguirre

Thanks, I did it too, but I'd like to understand how it could work without modification...

Veldars avatar Feb 19 '18 15:02 Veldars

I think it's because of some change that twitter made in its way of authenticating

josejaguirre avatar Feb 19 '18 15:02 josejaguirre

One question how do you end on different domain? Because, popup should go back to application. So I am creating popup from http://localhost:3000 and after authentication in popup will be opened http://localhost:3000/#callback? This is same host. What is your configuration for callback URL on Twitter application?

ivanvs avatar Feb 22 '18 09:02 ivanvs

@josejaguirre, I'm experiencing the same issue, could you please elaborate a little bit on a workaround for it?

sherlaimov avatar Aug 06 '18 19:08 sherlaimov

@sherlaimov hi! sure.

I used the process where the application redirects to a twitter login and then returns to the application using the callback I hope it serves you.

I was using node for that, i used https://github.com/drudge/passport-twitter-token library.

The steps you took were the following:

1.- Node Backend Use the library and create custom url for get request token from twitter link (https://api.twitter.com/oauth/request_token) 2.- React Component Edit getRequestToken from TwitterLogin and use the custom link and get the oauth_token prop 3.- React Component Redirect https://api.twitter.com/oauth/authenticate?oauth_token=${oauth_token} 4.- Twitter Setup Twitter app callback to return to your application 5.- Node Backend Setup authorization middleware using callback url.

josejaguirre avatar Aug 06 '18 21:08 josejaguirre

@josejaguirre thank you for you response, I also use NodeJS, in fact I tried following through @ivanvs's tutorial on implementing Twitter Authorization with React, however, I'm using KoaJS and had to use the oAuth module to authorize my 'node-fetch' requests - all seem to be working just fine, except for the frontend/react part.

Can you please explain what kind of customized link should be used in getRequestToken? I'm fetching the following requestTokenUrl link http://localhost:8080/auth/twitter/reverse in getRequestToken and it does return an oauth_token which is passed to a popup with location of https://api.twitter.com/oauth/authenticate?oauth_token=${data.oauth_token}&force_login=${this.props.forceLogin}.

My react app is running on port 3000, could the port difference be the reason causing the CORS issue?

sherlaimov avatar Aug 07 '18 08:08 sherlaimov

@ivanvs you are right, it is working now, thank you. It's clearly my gap in knowledge of what CORS really is.

sherlaimov avatar Aug 07 '18 21:08 sherlaimov

Hey Guys i write a react componet to login to OPENID but have a error : Failed to load https://sso.csoc.net/openid/authorize?response_type=code&client_id=948084&redirect_uri=https%3A%2F%2Flocalhost%3A4000%2Fopenid%2Fcallback&scope=openid%20auth_web%20openid%20profile%20email&state=qmICanszt40y7HQphWsmd7zg:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. client React : https://localhot:3000 Expres server : https://localhot:4000 connect to server authentication How i can fix by pass CORS ?

i try set header :

const customHeader = {}; customHeader['Access-Control-Allow-Origin'] = ''; customHeader['Origin'] = ''; customHeader['Accept'] = 'application/json'; customHeader['Content-Type'] = 'application/json';

longvd89 avatar Dec 05 '18 10:12 longvd89

Hey Guys i write a react componet to login to OPENID but have a error : Failed to load https://sso.csoc.net/openid/authorize?response_type=code&client_id=948084&redirect_uri=https%3A%2F%2Flocalhost%3A4000%2Fopenid%2Fcallback&scope=openid%20auth_web%20openid%20profile%20email&state=qmICanszt40y7HQphWsmd7zg:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. client React : https://localhot:3000 Expres server : https://localhot:4000 connect to server authentication How i can fix by pass CORS ?

i try set header :

const customHeader = {}; customHeader['Access-Control-Allow-Origin'] = ''; customHeader['Origin'] = ''; customHeader['Accept'] = 'application/json'; customHeader['Content-Type'] = 'application/json';

same issue +1

jjnanthakumar avatar Feb 03 '21 14:02 jjnanthakumar