-
Notifications
You must be signed in to change notification settings - Fork 555
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 IE default redirect url #1373
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
@@ -37,6 +37,15 @@ describe('setup', () => { | |||
const model = mock.calls[0][1].toJS(); | |||
expect(model.auth.redirectUrl).toBe('https://test.com/path/'); | |||
}); | |||
it('default redirectUrl should work when `window.location.origin` is not available', () => { | |||
setURL('https://test.com/path/#not-this-part', { noOrigin: true }); | |||
const options = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason why you have the declaration separate from the usage, since you're hardcoding the rest of the parameters too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easy to copy/paste later if needed 😬
var url = 'https://test.com/example'; | ||
expect(getOriginFromUrl(url)).toBe('https://test.com'); | ||
}); | ||
it('should use add the `port` when available', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use add
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use add include
const mapping = { | ||
'https://localhost:3000/foo?id=1': { | ||
href: 'https://localhost:3000/foo?id=1', | ||
protocol: 'https:', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protocol should not include the :
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the function does return the protocol with a colon:
// http://banana.com
host:"banana.com"
hostname:"banana.com"
href:"http://banana.com"
protocol:"http:"
Wikipedia says that protocol is:
A non-empty scheme component followed by a colon
... which tells me that protocol should not include it. That said, type this into your console:
> window.location
...
< protocol: "https:"
The built-in URL
object (MDN) has the colon so I think this is the right implementation. Again, in the console:
> var url = new URL(window.location.toString()); url;
...
< protocol: "https:"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lucho is discovering all the greatness of javascript. our boy is growing 😝
protocol: 'https:', | ||
host: 'auth0.com', | ||
hostname: 'auth0.com', | ||
port: undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you return undefined
or 80
(default)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's text parsing, silly! No port in the text === no port found
search: '', | ||
hash: '' | ||
}, | ||
'https://auth0.com#access_token=foo': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I enter manage.auth0.com, the #
is put after the /
. .e.g.: https://manage.auth0.com/#/applications
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/# and # is the same thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried:
- https://manage.auth0.com/#/applications -> fine
- https://manage.auth0.com#/applications -> redirs to https://manage.auth0.com/#/applications
- https://manage.auth0.com/#applications -> no content in the frame
- https://manage.auth0.com#applications -> no content in the frame
So as how I see it, I don't think they are the same. Maybe I'm wrong? Anyway, just add an extra case to test that scenario where the #
is after the /
such as https://manage.auth0.com/#/applications
.
port: undefined, | ||
pathname: '', | ||
search: '', | ||
hash: '#access_token=foo' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does hash includes the #
? Same as port property, it shouldn't. It's already implied in the property name 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as protocol
above, browser parsing with URL
includes the #
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it's what window.location.hash
returns
@@ -273,7 +273,8 @@ function extractAuthOptions(options) { | |||
// if responseType was not set and there is a redirectUrl, it defaults to code. Otherwise token. | |||
responseType = typeof responseType === 'string' ? responseType : redirectUrl ? 'code' : 'token'; | |||
// now we set the default because we already did the validation | |||
redirectUrl = redirectUrl || `${window.location.origin}${window.location.pathname}`; | |||
redirectUrl = | |||
redirectUrl || `${getOriginFromUrl(window.location.href)}${window.location.pathname}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this alternative of not using window.location.origin
work in every scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, if anything, it's way more reliable, since works across all browsers.
expect(getOriginFromUrl(null)).toBe(undefined); | ||
}); | ||
it('should use an anchor to parse the url and return the origin', function() { | ||
var url = 'https://test.com/example'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about http
URLs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushed some tests with http
@@ -1,5 +1,29 @@ | |||
export function parseUrl(str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it breaking to remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope. internal use only
}); | ||
}); | ||
describe('getLocationFromUrl', function() { | ||
const mapping = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to add a subdomain test here
const mapping = { | ||
'https://localhost:3000/foo?id=1': { | ||
href: 'https://localhost:3000/foo?id=1', | ||
protocol: 'https:', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the function does return the protocol with a colon:
// http://banana.com
host:"banana.com"
hostname:"banana.com"
href:"http://banana.com"
protocol:"http:"
Wikipedia says that protocol is:
A non-empty scheme component followed by a colon
... which tells me that protocol should not include it. That said, type this into your console:
> window.location
...
< protocol: "https:"
The built-in URL
object (MDN) has the colon so I think this is the right implementation. Again, in the console:
> var url = new URL(window.location.toString()); url;
...
< protocol: "https:"
var url = 'https://test.com/example'; | ||
expect(getOriginFromUrl(url)).toBe('https://test.com'); | ||
}); | ||
it('should use add the `port` when available', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use add include
protocol: 'https:', | ||
host: 'auth0.com', | ||
hostname: 'auth0.com', | ||
port: undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's text parsing, silly! No port in the text === no port found
port: undefined, | ||
pathname: '', | ||
search: '', | ||
hash: '#access_token=foo' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as protocol
above, browser parsing with URL
includes the #
} | ||
|
||
export function getOriginFromUrl(url) { | ||
if (!url) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're catching an empty string here but ... 👇
src/utils/url_utils.js
Outdated
return undefined; | ||
} | ||
var parsed = getLocationFromUrl(url); | ||
var origin = parsed.protocol + '//' + parsed.hostname; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... this is also a source of an error if you just pass in a string:
> getLocationFromUrl('banana')
< null
If there is no match then null
is returned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. pushed a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
fix #1361