Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
feat(project): use aurelia-pal for window and document
Browse files Browse the repository at this point in the history
  • Loading branch information
doktordirk committed Jun 1, 2016
1 parent 91e1589 commit fdbb918
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
5 changes: 3 additions & 2 deletions src/aurelia-authentication.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');
Expand Down
7 changes: 4 additions & 3 deletions src/authentication.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
}
23 changes: 12 additions & 11 deletions src/baseConfig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {PLATFORM} from 'aurelia-pal';
import {join} from 'aurelia-path';
import extend from 'extend';
import * as LogManager from 'aurelia-logging';
Expand Down Expand Up @@ -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';
Expand All @@ -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: ',',
Expand All @@ -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'],
Expand All @@ -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: ' ',
Expand All @@ -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: '+',
Expand All @@ -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: ' ',
Expand All @@ -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: ' ',
Expand All @@ -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: ' ',
Expand All @@ -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',
Expand All @@ -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: ' ',
Expand Down
11 changes: 6 additions & 5 deletions src/popup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {PLATFORM, DOM} from 'aurelia-pal';
import {parseQueryString} from 'aurelia-path';
import extend from 'extend';

Expand All @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 = [];
Expand Down
13 changes: 4 additions & 9 deletions src/storage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {PLATFORM} from 'aurelia-pal';
import {inject} from 'aurelia-dependency-injection';

import {BaseConfig} from './baseConfig';
Expand All @@ -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.