Permalink
Browse files

feat(project): use aurelia-pal for window and document

  • Loading branch information...
doktordirk committed May 29, 2016
1 parent 91e1589 commit fdbb9189f14200d4586a7a5f5d75715ce632d7c1
Showing with 29 additions and 30 deletions.
  1. +3 −2 src/aurelia-authentication.js
  2. +4 −3 src/authentication.js
  3. +12 −11 src/baseConfig.js
  4. +6 −5 src/popup.js
  5. +4 −9 src/storage.js
@@ -1,5 +1,6 @@
import {HttpClient} from 'aurelia-fetch-client';
import {Config, Rest} from 'aurelia-api';
import {PLATFORM} from 'aurelia-pal';
import {AuthService} from './authService';
import {AuthorizeStep} from './authorizeStep';
@@ -16,8 +17,8 @@ import './authFilter';
*/
function configure(aurelia, config) {
// ie9 polyfill
if (!window.location.origin) {
window.location.origin = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
if (!PLATFORM.location.origin) {
PLATFORM.location.origin = PLATFORM.location.protocol + '//' + PLATFORM.location.hostname + (PLATFORM.location.port ? ':' + PLATFORM.location.port : '');
}
aurelia.globalResources('./authFilter');
@@ -1,3 +1,4 @@
import {PLATFORM} from 'aurelia-pal';
import {inject} from 'aurelia-dependency-injection';
import {deprecated} from 'aurelia-metadata';
import * as LogManager from 'aurelia-logging';
@@ -150,7 +151,7 @@ export class Authentication {
if (this.accessToken && this.accessToken.split('.').length === 3) {
try {
const base64 = this.accessToken.split('.')[1].replace(/-/g, '+').replace(/_/g, '/');
payload = JSON.parse(decodeURIComponent(escape(window.atob(base64))));
payload = JSON.parse(decodeURIComponent(escape(atob(base64))));
} catch (e) {
payload = null;
}
@@ -256,9 +257,9 @@ export class Authentication {
return;
}
if (typeof redirectUrl === 'string') {
window.location.href = window.encodeURI(redirectUrl);
PLATFORM.location.href = encodeURI(redirectUrl);
} else if (defaultRedirectUrl) {
window.location.href = defaultRedirectUrl;
PLATFORM.location.href = defaultRedirectUrl;
}
}
}
@@ -1,3 +1,4 @@
import {PLATFORM} from 'aurelia-pal';
import {join} from 'aurelia-path';
import extend from 'extend';
import * as LogManager from 'aurelia-logging';
@@ -128,7 +129,7 @@ export class BaseConfig {
withCredentials = true;
// Controls how the popup is shown for different devices (Options: 'browser' or 'mobile')
platform = 'browser';
// Determines the `window` property name upon which aurelia-authentication data is stored (Default: `window.localStorage`)
// Determines the `PLATFORM` property name upon which aurelia-authentication data is stored (Default: `PLATFORM.localStorage`)
storage = 'localStorage';
// The key used for storing the authentication response locally
storageKey = 'aurelia_authentication';
@@ -140,7 +141,7 @@ export class BaseConfig {
name: 'facebook',
url: '/auth/facebook',
authorizationEndpoint: 'https://www.facebook.com/v2.5/dialog/oauth',
redirectUri: window.location.origin + '/',
redirectUri: PLATFORM.location.origin + '/',
requiredUrlParams: ['display', 'scope'],
scope: ['email'],
scopeDelimiter: ',',
@@ -152,7 +153,7 @@ export class BaseConfig {
name: 'google',
url: '/auth/google',
authorizationEndpoint: 'https://accounts.google.com/o/oauth2/auth',
redirectUri: window.location.origin,
redirectUri: PLATFORM.location.origin,
requiredUrlParams: ['scope'],
optionalUrlParams: ['display', 'state'],
scope: ['profile', 'email'],
@@ -170,7 +171,7 @@ export class BaseConfig {
name: 'github',
url: '/auth/github',
authorizationEndpoint: 'https://github.com/login/oauth/authorize',
redirectUri: window.location.origin,
redirectUri: PLATFORM.location.origin,
optionalUrlParams: ['scope'],
scope: ['user:email'],
scopeDelimiter: ' ',
@@ -181,7 +182,7 @@ export class BaseConfig {
name: 'instagram',
url: '/auth/instagram',
authorizationEndpoint: 'https://api.instagram.com/oauth/authorize',
redirectUri: window.location.origin,
redirectUri: PLATFORM.location.origin,
requiredUrlParams: ['scope'],
scope: ['basic'],
scopeDelimiter: '+',
@@ -191,7 +192,7 @@ export class BaseConfig {
name: 'linkedin',
url: '/auth/linkedin',
authorizationEndpoint: 'https://www.linkedin.com/uas/oauth2/authorization',
redirectUri: window.location.origin,
redirectUri: PLATFORM.location.origin,
requiredUrlParams: ['state'],
scope: ['r_emailaddress'],
scopeDelimiter: ' ',
@@ -203,15 +204,15 @@ export class BaseConfig {
name: 'twitter',
url: '/auth/twitter',
authorizationEndpoint: 'https://api.twitter.com/oauth/authenticate',
redirectUri: window.location.origin,
redirectUri: PLATFORM.location.origin,
oauthType: '1.0',
popupOptions: { width: 495, height: 645 }
},
twitch: {
name: 'twitch',
url: '/auth/twitch',
authorizationEndpoint: 'https://api.twitch.tv/kraken/oauth2/authorize',
redirectUri: window.location.origin,
redirectUri: PLATFORM.location.origin,
requiredUrlParams: ['scope'],
scope: ['user_read'],
scopeDelimiter: ' ',
@@ -223,7 +224,7 @@ export class BaseConfig {
name: 'live',
url: '/auth/live',
authorizationEndpoint: 'https://login.live.com/oauth20_authorize.srf',
redirectUri: window.location.origin,
redirectUri: PLATFORM.location.origin,
requiredUrlParams: ['display', 'scope'],
scope: ['wl.emails'],
scopeDelimiter: ' ',
@@ -235,7 +236,7 @@ export class BaseConfig {
name: 'yahoo',
url: '/auth/yahoo',
authorizationEndpoint: 'https://api.login.yahoo.com/oauth2/request_auth',
redirectUri: window.location.origin,
redirectUri: PLATFORM.location.origin,
scope: [],
scopeDelimiter: ',',
oauthType: '2.0',
@@ -245,7 +246,7 @@ export class BaseConfig {
name: 'bitbucket',
url: '/auth/bitbucket',
authorizationEndpoint: 'https://bitbucket.org/site/oauth2/authorize',
redirectUri: window.location.origin + '/',
redirectUri: PLATFORM.location.origin + '/',
requiredUrlParams: ['scope'],
scope: ['email'],
scopeDelimiter: ' ',
@@ -1,3 +1,4 @@
import {PLATFORM, DOM} from 'aurelia-pal';
import {parseQueryString} from 'aurelia-path';
import extend from 'extend';
@@ -12,7 +13,7 @@ export class Popup {
this.url = url;
const optionsString = buildPopupWindowOptions(options || {});
this.popupWindow = window.open(url, windowName, optionsString);
this.popupWindow = PLATFORM.global.open(url, windowName, optionsString);
if (this.popupWindow && this.popupWindow.focus) {
this.popupWindow.focus();
@@ -28,7 +29,7 @@ export class Popup {
return;
}
const parser = document.createElement('a');
const parser = DOM.createElement('a');
parser.href = event.url;
if (parser.search || parser.hash) {
@@ -60,7 +61,7 @@ export class Popup {
let errorData;
try {
if (this.popupWindow.location.host === document.location.host
if (this.popupWindow.location.host === DOM.location.host
&& (this.popupWindow.location.search || this.popupWindow.location.hash)) {
const qs = parseUrl(this.popupWindow.location);
@@ -102,8 +103,8 @@ const buildPopupWindowOptions = options => {
const extended = extend({
width: width,
height: height,
left: window.screenX + ((window.outerWidth - width) / 2),
top: window.screenY + ((window.outerHeight - height) / 2.5)
left: PLATFORM.global.screenX + ((PLATFORM.global.outerWidth - width) / 2),
top: PLATFORM.global.screenY + ((PLATFORM.global.outerHeight - height) / 2.5)
}, options);
let parts = [];
@@ -1,3 +1,4 @@
import {PLATFORM} from 'aurelia-pal';
import {inject} from 'aurelia-dependency-injection';
import {BaseConfig} from './baseConfig';
@@ -9,20 +10,14 @@ export class Storage {
}
get(key) {
if (window[this.config.storage]) {
return window[this.config.storage].getItem(key);
}
return PLATFORM.global[this.config.storage].getItem(key);
}
set(key, value) {
if (window[this.config.storage]) {
return window[this.config.storage].setItem(key, value);
}
PLATFORM.global[this.config.storage].setItem(key, value);
}
remove(key) {
if (window[this.config.storage]) {
return window[this.config.storage].removeItem(key);
}
PLATFORM.global[this.config.storage].removeItem(key);
}
}

0 comments on commit fdbb918

Please sign in to comment.