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

Don't reference window in default options if it doesn't exist #73

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import { isUndefined } from './utils.js';


function getCookieDomain() {
return isUndefined(window) ? '' : `${window.location.hostname}`;
}

function getCookieDomainUrl(path = '') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contextually, you are not returning CookieDomainUrl but redirectUri, so getRedirectUri would be a much better name for this function.

return isUndefined(window) ? path : `${window.location.origin}${path}`;
}
/**
* Default configuration
*/
Expand All @@ -13,7 +23,7 @@ export default {
storageType: 'localStorage',
storageNamespace: 'vue-authenticate',
cookieStorage: {
domain: typeof(window) === 'undefined' ? '' : window.location.hostname,
domain: getCookieDomain(),
path: '/',
secure: false
},
Expand Down Expand Up @@ -55,7 +65,7 @@ export default {
name: 'facebook',
url: '/auth/facebook',
authorizationEndpoint: 'https://www.facebook.com/v2.5/dialog/oauth',
redirectUri: typeof(window) === 'undefined' ? '/' : window.location.origin + '/',
redirectUri: getCookieDomainUrl('/'),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not good. You are using window.location.hostname for redirectUri. That information is only "{domain_name}.{TLD}" => "github.com". This means that if you have site on https, if you setup only hostname as your redirectUri, you will be redirected to http version of the site.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack good point, this time around missed the distinction that we were using hostname in just the first domain, origin in the rest. Fixing.

requiredUrlParams: ['display', 'scope'],
scope: ['email'],
scopeDelimiter: ',',
Expand All @@ -68,7 +78,7 @@ export default {
name: 'google',
url: '/auth/google',
authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth',
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
redirectUri: getCookieDomainUrl(),
requiredUrlParams: ['scope'],
optionalUrlParams: ['display'],
scope: ['profile', 'email'],
Expand All @@ -83,7 +93,7 @@ export default {
name: 'github',
url: '/auth/github',
authorizationEndpoint: 'https://github.com/login/oauth/authorize',
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
redirectUri: getCookieDomainUrl(),
optionalUrlParams: ['scope'],
scope: ['user:email'],
scopeDelimiter: ' ',
Expand All @@ -95,7 +105,7 @@ export default {
name: 'instagram',
url: '/auth/instagram',
authorizationEndpoint: 'https://api.instagram.com/oauth/authorize',
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
redirectUri: getCookieDomainUrl(),
requiredUrlParams: ['scope'],
scope: ['basic'],
scopeDelimiter: '+',
Expand All @@ -107,7 +117,7 @@ export default {
name: 'twitter',
url: '/auth/twitter',
authorizationEndpoint: 'https://api.twitter.com/oauth/authenticate',
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
redirectUri: getCookieDomainUrl(),
oauthType: '1.0',
popupOptions: { width: 495, height: 645 }
},
Expand All @@ -116,7 +126,7 @@ export default {
name: 'bitbucket',
url: '/auth/bitbucket',
authorizationEndpoint: 'https://bitbucket.org/site/oauth2/authorize',
redirectUri: typeof(window) === 'undefined' ? '/' : window.location.origin + '/',
redirectUri: getCookieDomainUrl('/'),
optionalUrlParams: ['scope'],
scope: ['email'],
scopeDelimiter: ' ',
Expand All @@ -128,7 +138,7 @@ export default {
name: 'linkedin',
url: '/auth/linkedin',
authorizationEndpoint: 'https://www.linkedin.com/oauth/v2/authorization',
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
redirectUri: getCookieDomainUrl(),
requiredUrlParams: ['state'],
scope: ['r_emailaddress'],
scopeDelimiter: ' ',
Expand All @@ -141,7 +151,7 @@ export default {
name: 'live',
url: '/auth/live',
authorizationEndpoint: 'https://login.live.com/oauth20_authorize.srf',
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
redirectUri: getCookieDomainUrl(),
requiredUrlParams: ['display', 'scope'],
scope: ['wl.emails'],
scopeDelimiter: ' ',
Expand All @@ -154,7 +164,7 @@ export default {
name: null,
url: '/auth/oauth1',
authorizationEndpoint: null,
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
redirectUri: getCookieDomainUrl(),
oauthType: '1.0',
popupOptions: null
},
Expand All @@ -163,7 +173,7 @@ export default {
name: null,
url: '/auth/oauth2',
clientId: null,
redirectUri: typeof(window) === 'undefined' ? '' : window.location.origin,
redirectUri: getCookieDomainUrl(),
authorizationEndpoint: null,
defaultUrlParams: ['response_type', 'client_id', 'redirect_uri'],
requiredUrlParams: null,
Expand Down