-
Notifications
You must be signed in to change notification settings - Fork 493
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
Ignore messages that are not from Auth0's iframe #406
Comments
This is in our backlog. We need to figure it out a way to ignore posted messages that are not from our iframe. I'll not add anything specific to webpack at the moment, but this will be fixed in the near future |
We are having the same issue with Redux Devtools, so a general solution would be appreciated. |
It will be general. We'll probably prefix our own messages with |
Just found out this huge problem. It seems that facebook's SDK causes renewAuth's callback to be triggered without error but the response contains invalid data. |
Same issue here. |
Hey.. Can any of you create a repro project so I can test this? I know what the problem is, but I can't reproduce it 😭 |
I use this react redux starter kit: https://github.com/davezuko/react-redux-starter-kit I'll try to create a repro project. |
Thanks. I don't know if we can effectively fix this at all. We don't have control on how the messages are posted... // this code goes inside the callback.html file (or your callback route)
auth0.parseHash(window.location.hash, function (err, data) {
parent.postMessage(err || data, "http://localhost:3000/");
}); Since this code lives outside of auth0.js, there's no way to know if the message is coming from the callback itself or from elsewhere. |
Is it possible to enrich the data somehow? Like data.source = 'auth0'. It will be along the line of your previous thoughts: 'prefix our own messages with auth:[...]'. |
nope, because this code lives outside of auth0.js. This is custom code that users write. |
This code is auth0's code, right? why not check the data source before destroying? Like Sandrinodimattia add this line before destroying: In my case, I need to add this: For this to be solved for general cases, shouldn't the code just add a data.source or something and check that before destroying? |
This is auth0's code, yes. For a webpack fix, we'd need to add: For a redux dev tools fix, we'd need to add: This won't scale, because lots of iframes sends data via postMessage. There's no way we blacklist every possible type of message that can happen. |
You have no control on others' code but the silent callback page is under control of the developer so he can enrich (ex: Add a string) the posted message. Then you can allow to specify the same string on renewAuth's options. When handling posted data, if the configured data is missing you ignore it. |
Yeah, that will work, but the best way is to receive something from the back end that we can check, so the developer won't need to do anything. |
Good to know it will be fixed soon! At the moment I had to delay Facebook's SDK initialization to avoid getting unwnated posts. |
Yeah.. there are a few alternatives to fix this in our client, but this will be better handled in the back end. I'm not sure what's the ETA on that, but it's coming. |
Mmm the data comes from the parseHash function. Maybe it should include in the data object a "source" property with some specific value. And in the iframe handler check the source before destroying. web-auth/index.js function buildParseHashResponse(qsParams, appStatus, token) {
return {
accessToken: qsParams.access_token || null,
idToken: qsParams.id_token || null,
idTokenPayload: token || null,
appStatus: appStatus || null,
refreshToken: qsParams.refresh_token || null,
state: qsParams.state || null,
expiresIn: qsParams.expires_in ? parseInt(qsParams.expires_in, 10) : null,
tokenType: qsParams.token_type || null,
_source: 'auth0js'
};
} helper/iframe-handler.js IframeHandler.prototype.messageEventListener = function (e) {
if (e.data && e.data._source === 'auth0js') {
this.destroy();
this.callbackHandler(e.data);
}
}; I tested it a little bit and seems to be working. Of course It might be necessary to add this special field on parseHash error response. But I'm not really sure. :) |
I have just discovered this issue too. My $0.02: Allow the Iframe helper to accept an event processor which return true if the desired event was found or false otherwise. I don't think it's really the responsibility of the Iframe helper to decide if the event is the one we're looking for or not. Instead, the main auth0 logic should do that. It would be super nice if we could overload that too, so we could customise it a bit more... |
This was fixed in #432 - it's still not documented though. |
Hey @luisrudge any update on documentation around this? I followed @oliverlloyd's suggestion from #429 but that didn't work. We're still seeing |
@gilesbutler Sorry, this is not in the docs yet. You have to use the var auth0 = new auth0.WebAuth({
domain: "{YOUR_AUTH0_DOMAIN}",
clientID: "{YOUR_AUTH0_CLIENT_ID}"
});
var options = {
//other options
postMessageDataType: 'my-custom-data-type'
};
auth0.renewAuth(options, (err, authResult)=> {
console.log(err, authResult);
}); And then in your callback page, you have to call it like this: <!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
parent.postMessage({
hash: window.location.hash,
type: 'my-custom-data-type'
}, "https://localhost:3000/");
</script>
</head>
<body></body>
</html> |
What is the benefit of using |
we listen to different events based on that param:
auth0.js/src/helper/iframe-handler.js Line 40 in bdce0d5
|
Thanks for getting back to me @luisrudge unfortunately still can't get this to work. We're using React-router so our callback page is just a route that triggers a SilentCallback component...
This is how we're calling
So
|
does your route gets called at all? does it work if you have just a static html page instead of letting react router handle that? |
@luisrudge This is not working for us neither.
const webAuth = new auth0.WebAuth({
domain: 'ourDomain.auth0.com',
clientID: 'OUR_CLIENT_ID',
postMessageDataType: 'custom-type'
});
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
parent.postMessage({
hash: window.location.hash,
type: 'custom-type'
}, window.location.origin.concat('/'));
</script>
</head>
<body></body>
</html> And still getting the iframe closed by other browser extensions. Can you please reopen this issue at least until the documentation is updated? |
Can you build a sample repo where I can reproduce this issue? It'd be good to have the dependencies that use postMessage as well so I can reproduce on my machine too. |
I think it would be better if you can give us a working example, since we don't really know how we should implement the renew auth in the new flow. The thing is that is you have a browser extension like vue-dev-tools or similar, the iframe is still being closed by the browser extension with the authReault having useless data. |
@buccfer, If your development extensions are causing issues then I recommend turning them off while developing a prototype. Here's some snippets from some working code I used when I developed the original patch for this functionality: Callback html page:
This part is written in typescript, but the general gist of the code should be clear:
|
Just some feedback to let people know luisrudge's code sample above worked perfectly for me. |
@buccfer @gilesbutler I noticed you both are not using |
although @shorn said my example works and I didn't use it as well, so that may not be the issue. |
@luisrudge code: var auth0 = new auth0.WebAuth({
domain: "{YOUR_AUTH0_DOMAIN}",
clientID: "{YOUR_AUTH0_CLIENT_ID}",
postMessageDataType: 'my-custom-data-type'
}); @aaronchilcott code: var data = {
audience: `https://${AUTH_CONFIG.domain}/userinfo`,
scope: 'openid',
responseType: 'id_token token',
usePostMessage: true,
postMessageDataType: 'auth0:silent-authentication',
redirectUri: AUTH_CONFIG.silentCallbackURL,
};
this.auth0.renewAuth(data, (err, authResult)=>{ I see they are different. In one the postMessageDataType is in the auth0.WebAuth constructor and in the other it is in the renewAuth options. |
@luisrudge - sorry, I just meant the |
@shorn Can you please share your implementation? Since none of the examples found so far work for me. Have you tested it with browser extensions like vue-dev-tools or augury? They still close the iframe with useless data. @aaronchilcott What's the point in disabling the extensions? Shouldn't auth0js work independently of the browser extensions the user has enabled? That's something you cannot control in production. @luisrudge Is there any chance to update the doc? |
@buccfer it should work despite extensions. Please create a sample with a list of extensions so I can reproduce the issue. Please include the steps I have to follow to cause the issue (like: click to open the popup, then click the XYZ button in the extension etc) |
@luisrudge Finally I got something different. Now the renewAuth gives me an error:
Do I have to configure the option to switch how the id_tokens are signed from HS256 to RS256 in our client? |
Correct. There's a similar discussion here: #303 (comment) |
The |
☝️ yes @dimitrovs that <3 |
@dimitrovs you're totally write. I'll edit my snippet to reflect that. thanks! |
Thank God I found this thread. Spent 9 hours trying to debug this issue with renewAuth. Turns out it was one of the chrome developer tools - likely Vue.js debugger. Turn it off, and it works fine! |
This was very annoying, thank you for the direction. I've submitted a PR to fix this in the auth0 examples too auth0-samples/auth0-react-samples#44 |
So renewAuth is not working for me with postMessage enabled. The request is getting cancelled in the browser. In the iframe it looks like other events are being sent (before the code reaches parseHash) which causes the iframe to be destroyed.
Now I have this when running locally (because of an event from webpack) and when running a deployed version (because of an empty event). Here is what fixed it for me in the iframe handler:
The text was updated successfully, but these errors were encountered: