From 3b0e4fed082f55f0b765c4da903493aa66446f0c Mon Sep 17 00:00:00 2001 From: Anthony Kirwan Date: Tue, 21 Oct 2014 11:18:57 -0500 Subject: [PATCH] Release: 0.5.2 --- README.md | 2 +- bower.json | 2 +- dist/ember-oauth2.amd.js | 4 ++-- dist/ember-oauth2.amd.min.js | 2 +- dist/ember-oauth2.js | 4 ++-- dist/ember-oauth2.min.js | 2 +- lib/ember-oauth2.js | 4 ++-- package.json | 2 +- yuidoc.json | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 95d14f3..33f64a0 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ JavaScript library for using OAuth 2.0 Implicit Grant flow (Client-Side Flow) fo This creates an OAuth 2.0 Ember object class for handling authentication with OAuth 2.0 providers. -Current Version: **[0.5.1](https://github.com/amkirwan/ember-oauth2/releases/tag/v0.5.1)** +Current Version: **[0.5.2](https://github.com/amkirwan/ember-oauth2/releases/tag/v0.5.2)** ## Dependencies diff --git a/bower.json b/bower.json index 82a82c9..cb7edf8 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ember-oauth2", - "version": "0.5.1", + "version": "0.5.2", "homepage": "https://github.com/amkirwan/ember-oauth2", "authors": [ "Anthony Kirwan " diff --git a/dist/ember-oauth2.amd.js b/dist/ember-oauth2.amd.js index f6b90f7..b3d41f9 100644 --- a/dist/ember-oauth2.amd.js +++ b/dist/ember-oauth2.amd.js @@ -8,7 +8,7 @@ define("ember-oauth2", * @overview OAuth2 library for Emberjs that stores tokens in the browsers localStorage * @license Licensed under MIT license * See https://raw.github.com/amkirwan/ember-oauth2/master/LICENSE - * @version 0.5.1 + * @version 0.5.2 * * @module ember-oauth2 * @class ember-oauth2 @@ -436,7 +436,7 @@ define("ember-oauth2", * @property {String} VERSION * @final */ - var VERSION = "0.5.1"; + var VERSION = "0.5.2"; /** * @method version diff --git a/dist/ember-oauth2.amd.min.js b/dist/ember-oauth2.amd.min.js index f3a085a..403fd19 100644 --- a/dist/ember-oauth2.amd.min.js +++ b/dist/ember-oauth2.amd.min.js @@ -1,2 +1,2 @@ /** ember-oauth2 | @version 0.5.1 | 21-10-2014 */ -!function(){var a,b,c,d;!function(){function e(a,b,d){for(var e,g,h=a.length,i=new Array(h),j=0,k=h;k>j;j++)e=a[j],"exports"===e?g=i[j]=d:i[j]=c(f(e,b));return{deps:i,exports:g}}function f(a,b){if("."!==a.charAt(0))return a;var c,d=a.split("/"),e=b.split("/");c=1===e.length?e:e.slice(0,-1);for(var f=0,g=d.length;g>f;f++){var h=d[f];if(".."===h)c.pop();else{if("."===h)continue;c.push(h)}}return c.join("/")}var g;g=Array.isArray?Array.isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)};var h={},i={},j={},k=!1;a=function(a,b,c){g(b)||(c=b,b=[]),h[a]={deps:b,callback:c}},d=c=b=function(a){if(j[a]!==k&&i.hasOwnProperty(a))return i[a];if(!h[a])throw new Error("Could not find module "+a);var b,c,d=h[a],f=!1;i[a]={};try{b=e(d.deps,a,i[a]),c=d.callback.apply(this,b.deps),f=!0}finally{f||(j[a]=k)}return b.exports?i[a]:i[a]=c},d.entries=d._eak_seen=h,d.clear=function(){d.entries=d._eak_seen=h={},i=j={}}}(),a("ember-oauth2",["ember","exports"],function(a,b){"use strict";var c=a["default"];b["default"]=c.Object.extend(c.Evented,{init:function(){this._super(),c.OAuth2&&c.OAuth2.config&&Object.keys(c.OAuth2.config).length?(c.Logger.warn("Ember.OAuth2.config is deprecated and will be removed in future versions. Set the config using window.ENV['ember-oauth2']"),this.providerConfig=c.OAuth2.config[this.get("providerId")]):this.providerConfig=window.ENV["ember-oauth2"][this.get("providerId")],this.set("statePrefix","state"),this.set("tokenPrefix","token"),this.setProperties(this.providerConfig),this.on("redirect",this.handleRedirect),this.on("success",this._onSuccess),this.on("error",this._onError)},version:function(){return d},uuid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0,c="x"===a?b:3&b|8;return c.toString(16)})},now:function(){return Math.round((new Date).getTime()/1e3)},requestObj:function(){var a={response_type:"token"};return a.providerId=this.get("providerId"),a.state=this.get("state"),a.client_id=this.get("clientId"),a.state=this.get("state"),this.get("scope")&&(a.scope=this.get("scope")),a},authUri:function(){this.get("state")||this.set("state",this.uuid());var a=this.get("authBaseUri");return a+="?response_type=token&redirect_uri="+encodeURIComponent(this.get("redirectUri"))+"&client_id="+encodeURIComponent(this.get("clientId"))+"&state="+encodeURIComponent(this.get("state")),this.get("scope")&&(a+="&scope="+encodeURIComponent(this.get(".scope")).replace("%20","+")),a},authorize:function(){if(!this.get("providerId"))throw new Error("No provider id given.");if(!this.get("clientId"))throw new Error("No client id given.");if(!this.get("authBaseUri"))throw new Error("No auth base uri given.");if(!this.get("redirectUri"))throw new Error("No redirect uri given.");var a=this.authUri();return this.clearStates(),this.saveState(this.get("state"),this.requestObj()),this.openWindow(a)},openWindow:function(a){var b=window.open(a,"Authorize","height=600, width=450");window.focus&&b&&b.focus();return new c.RSVP.Promise(function(a,c){b?a(b):c(new Error("Opening dialog login window failed."))})},authSuccess:function(a){return a.access_token},generateToken:function(a){var b={};return b.provider_id=this.get("providerId"),b.expires_in=this.expiresIn(a.expires_in),b.scope=this.get("scope"),b.access_token=a.access_token,b},expiresIn:function(a){return this.now()+parseInt(a,10)},onRedirect:function(a,b){c.Logger.warn("Ember.OAuth2.onRedirect is deprecated and will be removed in future versions. Please use .trigger('redirect') instead."),this.trigger("redirect",a,b)},handleRedirect:function(a,b){var c=this.parseCallback(a);if(this.authSuccess(c)){var d=this.getState(c.state);this.checkState(d),this.saveToken(this.generateToken(c)),this.trigger("success",d)}else this.trigger("error",c);b&&"function"==typeof b&&b()},_onSuccess:function(a){"function"==typeof this.onSuccess&&(c.Logger.warn("Ember.OAuth2.onSuccess is deprecated and will be removed in future versions. Bind your callbacks using .on('success', fn) instead."),this.onSuccess(a))},_onError:function(a){"function"==typeof this.onError&&(c.Logger.warn("Ember.OAuth2.onError is deprecated and will be removed in furture versions. Bind your callbacks using .on('error', fn) instead."),this.onError(a))},checkState:function(a){if(!a)throw new Error("Could not find state.");if(a.state!==this.get("state"))throw new Error("State returned from the server did not match the local saved state.")},parseCallback:function(a){for(var b,c={},d=a.substring(1),e=/([^#?&=]+)=([^&]*)/g;null!==(b=e.exec(d));)c[decodeURIComponent(b[1])]=decodeURIComponent(b[2]);return c},saveState:function(a,b){window.localStorage.setItem(this.get("statePrefix")+"-"+a,JSON.stringify(b))},getState:function(a){var b=JSON.parse(window.localStorage.getItem(this.get("statePrefix")+"-"+a));return window.localStorage.removeItem(this.get("statePrefix")+"-"+a),b},clearStates:function(){for(var a,b=new RegExp("^"+this.get("statePrefix")+"-.*","g"),c=[],d=0,e=window.localStorage.length;e>d;d++)a=window.localStorage.key(d),a.match(b)&&c.push(a);for(var f=0,g=c.length;g>f;f++)a=c[f],window.localStorage.removeItem(a);return c},saveToken:function(a){window.localStorage.setItem(this.get("tokenPrefix")+"-"+this.get("providerId"),JSON.stringify(a))},getToken:function(){var a=JSON.parse(window.localStorage.getItem(this.get("tokenPrefix")+"-"+this.get("providerId")));return a&&a.access_token?a:null},getAccessToken:function(){var a=this.getToken();return a?a.access_token:null},accessTokenIsExpired:function(){var a=this.getToken();return a?this.now()>=a.expires_in?!0:!1:!0},expireAccessToken:function(){var a=this.getToken();return a?(a.expires_in=0,void this.saveToken(a)):null}});var d="0.5.1";c.OAuth2&&(c.OAuth2.version=d)}),a("ember",[],function(){"use strict";return{"default":Ember}}),window.Ember.OAuth2=b("ember-oauth2")["default"]}(window); \ No newline at end of file +!function(){var a,b,c,d;!function(){function e(a,b,d){for(var e,g,h=a.length,i=new Array(h),j=0,k=h;k>j;j++)e=a[j],"exports"===e?g=i[j]=d:i[j]=c(f(e,b));return{deps:i,exports:g}}function f(a,b){if("."!==a.charAt(0))return a;var c,d=a.split("/"),e=b.split("/");c=1===e.length?e:e.slice(0,-1);for(var f=0,g=d.length;g>f;f++){var h=d[f];if(".."===h)c.pop();else{if("."===h)continue;c.push(h)}}return c.join("/")}var g;g=Array.isArray?Array.isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)};var h={},i={},j={},k=!1;a=function(a,b,c){g(b)||(c=b,b=[]),h[a]={deps:b,callback:c}},d=c=b=function(a){if(j[a]!==k&&i.hasOwnProperty(a))return i[a];if(!h[a])throw new Error("Could not find module "+a);var b,c,d=h[a],f=!1;i[a]={};try{b=e(d.deps,a,i[a]),c=d.callback.apply(this,b.deps),f=!0}finally{f||(j[a]=k)}return b.exports?i[a]:i[a]=c},d.entries=d._eak_seen=h,d.clear=function(){d.entries=d._eak_seen=h={},i=j={}}}(),a("ember-oauth2",["ember","exports"],function(a,b){"use strict";var c=a["default"];b["default"]=c.Object.extend(c.Evented,{init:function(){this._super(),c.OAuth2&&c.OAuth2.config&&Object.keys(c.OAuth2.config).length?(c.Logger.warn("Ember.OAuth2.config is deprecated and will be removed in future versions. Set the config using window.ENV['ember-oauth2']"),this.providerConfig=c.OAuth2.config[this.get("providerId")]):this.providerConfig=window.ENV["ember-oauth2"][this.get("providerId")],this.set("statePrefix","state"),this.set("tokenPrefix","token"),this.setProperties(this.providerConfig),this.on("redirect",this.handleRedirect),this.on("success",this._onSuccess),this.on("error",this._onError)},version:function(){return d},uuid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0,c="x"===a?b:3&b|8;return c.toString(16)})},now:function(){return Math.round((new Date).getTime()/1e3)},requestObj:function(){var a={response_type:"token"};return a.providerId=this.get("providerId"),a.state=this.get("state"),a.client_id=this.get("clientId"),a.state=this.get("state"),this.get("scope")&&(a.scope=this.get("scope")),a},authUri:function(){this.get("state")||this.set("state",this.uuid());var a=this.get("authBaseUri");return a+="?response_type=token&redirect_uri="+encodeURIComponent(this.get("redirectUri"))+"&client_id="+encodeURIComponent(this.get("clientId"))+"&state="+encodeURIComponent(this.get("state")),this.get("scope")&&(a+="&scope="+encodeURIComponent(this.get(".scope")).replace("%20","+")),a},authorize:function(){if(!this.get("providerId"))throw new Error("No provider id given.");if(!this.get("clientId"))throw new Error("No client id given.");if(!this.get("authBaseUri"))throw new Error("No auth base uri given.");if(!this.get("redirectUri"))throw new Error("No redirect uri given.");var a=this.authUri();return this.clearStates(),this.saveState(this.get("state"),this.requestObj()),this.openWindow(a)},openWindow:function(a){var b=window.open(a,"Authorize","height=600, width=450");window.focus&&b&&b.focus();return new c.RSVP.Promise(function(a,c){b?a(b):c(new Error("Opening dialog login window failed."))})},authSuccess:function(a){return a.access_token},generateToken:function(a){var b={};return b.provider_id=this.get("providerId"),b.expires_in=this.expiresIn(a.expires_in),b.scope=this.get("scope"),b.access_token=a.access_token,b},expiresIn:function(a){return this.now()+parseInt(a,10)},onRedirect:function(a,b){c.Logger.warn("Ember.OAuth2.onRedirect is deprecated and will be removed in future versions. Please use .trigger('redirect') instead."),this.trigger("redirect",a,b)},handleRedirect:function(a,b){var c=this.parseCallback(a);if(this.authSuccess(c)){var d=this.getState(c.state);this.checkState(d),this.saveToken(this.generateToken(c)),this.trigger("success",d)}else this.trigger("error",c);b&&"function"==typeof b&&b()},_onSuccess:function(a){"function"==typeof this.onSuccess&&(c.Logger.warn("Ember.OAuth2.onSuccess is deprecated and will be removed in future versions. Bind your callbacks using .on('success', fn) instead."),this.onSuccess(a))},_onError:function(a){"function"==typeof this.onError&&(c.Logger.warn("Ember.OAuth2.onError is deprecated and will be removed in furture versions. Bind your callbacks using .on('error', fn) instead."),this.onError(a))},checkState:function(a){if(!a)throw new Error("Could not find state.");if(a.state!==this.get("state"))throw new Error("State returned from the server did not match the local saved state.")},parseCallback:function(a){for(var b,c={},d=a.substring(1),e=/([^#?&=]+)=([^&]*)/g;null!==(b=e.exec(d));)c[decodeURIComponent(b[1])]=decodeURIComponent(b[2]);return c},saveState:function(a,b){window.localStorage.setItem(this.get("statePrefix")+"-"+a,JSON.stringify(b))},getState:function(a){var b=JSON.parse(window.localStorage.getItem(this.get("statePrefix")+"-"+a));return window.localStorage.removeItem(this.get("statePrefix")+"-"+a),b},clearStates:function(){for(var a,b=new RegExp("^"+this.get("statePrefix")+"-.*","g"),c=[],d=0,e=window.localStorage.length;e>d;d++)a=window.localStorage.key(d),a.match(b)&&c.push(a);for(var f=0,g=c.length;g>f;f++)a=c[f],window.localStorage.removeItem(a);return c},saveToken:function(a){window.localStorage.setItem(this.get("tokenPrefix")+"-"+this.get("providerId"),JSON.stringify(a))},getToken:function(){var a=JSON.parse(window.localStorage.getItem(this.get("tokenPrefix")+"-"+this.get("providerId")));return a&&a.access_token?a:null},getAccessToken:function(){var a=this.getToken();return a?a.access_token:null},accessTokenIsExpired:function(){var a=this.getToken();return a?this.now()>=a.expires_in?!0:!1:!0},expireAccessToken:function(){var a=this.getToken();return a?(a.expires_in=0,void this.saveToken(a)):null}});var d="0.5.2";c.OAuth2&&(c.OAuth2.version=d)}),a("ember",[],function(){"use strict";return{"default":Ember}}),window.Ember.OAuth2=b("ember-oauth2")["default"]}(window); \ No newline at end of file diff --git a/dist/ember-oauth2.js b/dist/ember-oauth2.js index c5cdc81..c35c070 100644 --- a/dist/ember-oauth2.js +++ b/dist/ember-oauth2.js @@ -120,7 +120,7 @@ define("ember-oauth2", * @overview OAuth2 library for Emberjs that stores tokens in the browsers localStorage * @license Licensed under MIT license * See https://raw.github.com/amkirwan/ember-oauth2/master/LICENSE - * @version 0.5.1 + * @version 0.5.2 * * @module ember-oauth2 * @class ember-oauth2 @@ -548,7 +548,7 @@ define("ember-oauth2", * @property {String} VERSION * @final */ - var VERSION = "0.5.1"; + var VERSION = "0.5.2"; /** * @method version diff --git a/dist/ember-oauth2.min.js b/dist/ember-oauth2.min.js index f3a085a..403fd19 100644 --- a/dist/ember-oauth2.min.js +++ b/dist/ember-oauth2.min.js @@ -1,2 +1,2 @@ /** ember-oauth2 | @version 0.5.1 | 21-10-2014 */ -!function(){var a,b,c,d;!function(){function e(a,b,d){for(var e,g,h=a.length,i=new Array(h),j=0,k=h;k>j;j++)e=a[j],"exports"===e?g=i[j]=d:i[j]=c(f(e,b));return{deps:i,exports:g}}function f(a,b){if("."!==a.charAt(0))return a;var c,d=a.split("/"),e=b.split("/");c=1===e.length?e:e.slice(0,-1);for(var f=0,g=d.length;g>f;f++){var h=d[f];if(".."===h)c.pop();else{if("."===h)continue;c.push(h)}}return c.join("/")}var g;g=Array.isArray?Array.isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)};var h={},i={},j={},k=!1;a=function(a,b,c){g(b)||(c=b,b=[]),h[a]={deps:b,callback:c}},d=c=b=function(a){if(j[a]!==k&&i.hasOwnProperty(a))return i[a];if(!h[a])throw new Error("Could not find module "+a);var b,c,d=h[a],f=!1;i[a]={};try{b=e(d.deps,a,i[a]),c=d.callback.apply(this,b.deps),f=!0}finally{f||(j[a]=k)}return b.exports?i[a]:i[a]=c},d.entries=d._eak_seen=h,d.clear=function(){d.entries=d._eak_seen=h={},i=j={}}}(),a("ember-oauth2",["ember","exports"],function(a,b){"use strict";var c=a["default"];b["default"]=c.Object.extend(c.Evented,{init:function(){this._super(),c.OAuth2&&c.OAuth2.config&&Object.keys(c.OAuth2.config).length?(c.Logger.warn("Ember.OAuth2.config is deprecated and will be removed in future versions. Set the config using window.ENV['ember-oauth2']"),this.providerConfig=c.OAuth2.config[this.get("providerId")]):this.providerConfig=window.ENV["ember-oauth2"][this.get("providerId")],this.set("statePrefix","state"),this.set("tokenPrefix","token"),this.setProperties(this.providerConfig),this.on("redirect",this.handleRedirect),this.on("success",this._onSuccess),this.on("error",this._onError)},version:function(){return d},uuid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0,c="x"===a?b:3&b|8;return c.toString(16)})},now:function(){return Math.round((new Date).getTime()/1e3)},requestObj:function(){var a={response_type:"token"};return a.providerId=this.get("providerId"),a.state=this.get("state"),a.client_id=this.get("clientId"),a.state=this.get("state"),this.get("scope")&&(a.scope=this.get("scope")),a},authUri:function(){this.get("state")||this.set("state",this.uuid());var a=this.get("authBaseUri");return a+="?response_type=token&redirect_uri="+encodeURIComponent(this.get("redirectUri"))+"&client_id="+encodeURIComponent(this.get("clientId"))+"&state="+encodeURIComponent(this.get("state")),this.get("scope")&&(a+="&scope="+encodeURIComponent(this.get(".scope")).replace("%20","+")),a},authorize:function(){if(!this.get("providerId"))throw new Error("No provider id given.");if(!this.get("clientId"))throw new Error("No client id given.");if(!this.get("authBaseUri"))throw new Error("No auth base uri given.");if(!this.get("redirectUri"))throw new Error("No redirect uri given.");var a=this.authUri();return this.clearStates(),this.saveState(this.get("state"),this.requestObj()),this.openWindow(a)},openWindow:function(a){var b=window.open(a,"Authorize","height=600, width=450");window.focus&&b&&b.focus();return new c.RSVP.Promise(function(a,c){b?a(b):c(new Error("Opening dialog login window failed."))})},authSuccess:function(a){return a.access_token},generateToken:function(a){var b={};return b.provider_id=this.get("providerId"),b.expires_in=this.expiresIn(a.expires_in),b.scope=this.get("scope"),b.access_token=a.access_token,b},expiresIn:function(a){return this.now()+parseInt(a,10)},onRedirect:function(a,b){c.Logger.warn("Ember.OAuth2.onRedirect is deprecated and will be removed in future versions. Please use .trigger('redirect') instead."),this.trigger("redirect",a,b)},handleRedirect:function(a,b){var c=this.parseCallback(a);if(this.authSuccess(c)){var d=this.getState(c.state);this.checkState(d),this.saveToken(this.generateToken(c)),this.trigger("success",d)}else this.trigger("error",c);b&&"function"==typeof b&&b()},_onSuccess:function(a){"function"==typeof this.onSuccess&&(c.Logger.warn("Ember.OAuth2.onSuccess is deprecated and will be removed in future versions. Bind your callbacks using .on('success', fn) instead."),this.onSuccess(a))},_onError:function(a){"function"==typeof this.onError&&(c.Logger.warn("Ember.OAuth2.onError is deprecated and will be removed in furture versions. Bind your callbacks using .on('error', fn) instead."),this.onError(a))},checkState:function(a){if(!a)throw new Error("Could not find state.");if(a.state!==this.get("state"))throw new Error("State returned from the server did not match the local saved state.")},parseCallback:function(a){for(var b,c={},d=a.substring(1),e=/([^#?&=]+)=([^&]*)/g;null!==(b=e.exec(d));)c[decodeURIComponent(b[1])]=decodeURIComponent(b[2]);return c},saveState:function(a,b){window.localStorage.setItem(this.get("statePrefix")+"-"+a,JSON.stringify(b))},getState:function(a){var b=JSON.parse(window.localStorage.getItem(this.get("statePrefix")+"-"+a));return window.localStorage.removeItem(this.get("statePrefix")+"-"+a),b},clearStates:function(){for(var a,b=new RegExp("^"+this.get("statePrefix")+"-.*","g"),c=[],d=0,e=window.localStorage.length;e>d;d++)a=window.localStorage.key(d),a.match(b)&&c.push(a);for(var f=0,g=c.length;g>f;f++)a=c[f],window.localStorage.removeItem(a);return c},saveToken:function(a){window.localStorage.setItem(this.get("tokenPrefix")+"-"+this.get("providerId"),JSON.stringify(a))},getToken:function(){var a=JSON.parse(window.localStorage.getItem(this.get("tokenPrefix")+"-"+this.get("providerId")));return a&&a.access_token?a:null},getAccessToken:function(){var a=this.getToken();return a?a.access_token:null},accessTokenIsExpired:function(){var a=this.getToken();return a?this.now()>=a.expires_in?!0:!1:!0},expireAccessToken:function(){var a=this.getToken();return a?(a.expires_in=0,void this.saveToken(a)):null}});var d="0.5.1";c.OAuth2&&(c.OAuth2.version=d)}),a("ember",[],function(){"use strict";return{"default":Ember}}),window.Ember.OAuth2=b("ember-oauth2")["default"]}(window); \ No newline at end of file +!function(){var a,b,c,d;!function(){function e(a,b,d){for(var e,g,h=a.length,i=new Array(h),j=0,k=h;k>j;j++)e=a[j],"exports"===e?g=i[j]=d:i[j]=c(f(e,b));return{deps:i,exports:g}}function f(a,b){if("."!==a.charAt(0))return a;var c,d=a.split("/"),e=b.split("/");c=1===e.length?e:e.slice(0,-1);for(var f=0,g=d.length;g>f;f++){var h=d[f];if(".."===h)c.pop();else{if("."===h)continue;c.push(h)}}return c.join("/")}var g;g=Array.isArray?Array.isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)};var h={},i={},j={},k=!1;a=function(a,b,c){g(b)||(c=b,b=[]),h[a]={deps:b,callback:c}},d=c=b=function(a){if(j[a]!==k&&i.hasOwnProperty(a))return i[a];if(!h[a])throw new Error("Could not find module "+a);var b,c,d=h[a],f=!1;i[a]={};try{b=e(d.deps,a,i[a]),c=d.callback.apply(this,b.deps),f=!0}finally{f||(j[a]=k)}return b.exports?i[a]:i[a]=c},d.entries=d._eak_seen=h,d.clear=function(){d.entries=d._eak_seen=h={},i=j={}}}(),a("ember-oauth2",["ember","exports"],function(a,b){"use strict";var c=a["default"];b["default"]=c.Object.extend(c.Evented,{init:function(){this._super(),c.OAuth2&&c.OAuth2.config&&Object.keys(c.OAuth2.config).length?(c.Logger.warn("Ember.OAuth2.config is deprecated and will be removed in future versions. Set the config using window.ENV['ember-oauth2']"),this.providerConfig=c.OAuth2.config[this.get("providerId")]):this.providerConfig=window.ENV["ember-oauth2"][this.get("providerId")],this.set("statePrefix","state"),this.set("tokenPrefix","token"),this.setProperties(this.providerConfig),this.on("redirect",this.handleRedirect),this.on("success",this._onSuccess),this.on("error",this._onError)},version:function(){return d},uuid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0,c="x"===a?b:3&b|8;return c.toString(16)})},now:function(){return Math.round((new Date).getTime()/1e3)},requestObj:function(){var a={response_type:"token"};return a.providerId=this.get("providerId"),a.state=this.get("state"),a.client_id=this.get("clientId"),a.state=this.get("state"),this.get("scope")&&(a.scope=this.get("scope")),a},authUri:function(){this.get("state")||this.set("state",this.uuid());var a=this.get("authBaseUri");return a+="?response_type=token&redirect_uri="+encodeURIComponent(this.get("redirectUri"))+"&client_id="+encodeURIComponent(this.get("clientId"))+"&state="+encodeURIComponent(this.get("state")),this.get("scope")&&(a+="&scope="+encodeURIComponent(this.get(".scope")).replace("%20","+")),a},authorize:function(){if(!this.get("providerId"))throw new Error("No provider id given.");if(!this.get("clientId"))throw new Error("No client id given.");if(!this.get("authBaseUri"))throw new Error("No auth base uri given.");if(!this.get("redirectUri"))throw new Error("No redirect uri given.");var a=this.authUri();return this.clearStates(),this.saveState(this.get("state"),this.requestObj()),this.openWindow(a)},openWindow:function(a){var b=window.open(a,"Authorize","height=600, width=450");window.focus&&b&&b.focus();return new c.RSVP.Promise(function(a,c){b?a(b):c(new Error("Opening dialog login window failed."))})},authSuccess:function(a){return a.access_token},generateToken:function(a){var b={};return b.provider_id=this.get("providerId"),b.expires_in=this.expiresIn(a.expires_in),b.scope=this.get("scope"),b.access_token=a.access_token,b},expiresIn:function(a){return this.now()+parseInt(a,10)},onRedirect:function(a,b){c.Logger.warn("Ember.OAuth2.onRedirect is deprecated and will be removed in future versions. Please use .trigger('redirect') instead."),this.trigger("redirect",a,b)},handleRedirect:function(a,b){var c=this.parseCallback(a);if(this.authSuccess(c)){var d=this.getState(c.state);this.checkState(d),this.saveToken(this.generateToken(c)),this.trigger("success",d)}else this.trigger("error",c);b&&"function"==typeof b&&b()},_onSuccess:function(a){"function"==typeof this.onSuccess&&(c.Logger.warn("Ember.OAuth2.onSuccess is deprecated and will be removed in future versions. Bind your callbacks using .on('success', fn) instead."),this.onSuccess(a))},_onError:function(a){"function"==typeof this.onError&&(c.Logger.warn("Ember.OAuth2.onError is deprecated and will be removed in furture versions. Bind your callbacks using .on('error', fn) instead."),this.onError(a))},checkState:function(a){if(!a)throw new Error("Could not find state.");if(a.state!==this.get("state"))throw new Error("State returned from the server did not match the local saved state.")},parseCallback:function(a){for(var b,c={},d=a.substring(1),e=/([^#?&=]+)=([^&]*)/g;null!==(b=e.exec(d));)c[decodeURIComponent(b[1])]=decodeURIComponent(b[2]);return c},saveState:function(a,b){window.localStorage.setItem(this.get("statePrefix")+"-"+a,JSON.stringify(b))},getState:function(a){var b=JSON.parse(window.localStorage.getItem(this.get("statePrefix")+"-"+a));return window.localStorage.removeItem(this.get("statePrefix")+"-"+a),b},clearStates:function(){for(var a,b=new RegExp("^"+this.get("statePrefix")+"-.*","g"),c=[],d=0,e=window.localStorage.length;e>d;d++)a=window.localStorage.key(d),a.match(b)&&c.push(a);for(var f=0,g=c.length;g>f;f++)a=c[f],window.localStorage.removeItem(a);return c},saveToken:function(a){window.localStorage.setItem(this.get("tokenPrefix")+"-"+this.get("providerId"),JSON.stringify(a))},getToken:function(){var a=JSON.parse(window.localStorage.getItem(this.get("tokenPrefix")+"-"+this.get("providerId")));return a&&a.access_token?a:null},getAccessToken:function(){var a=this.getToken();return a?a.access_token:null},accessTokenIsExpired:function(){var a=this.getToken();return a?this.now()>=a.expires_in?!0:!1:!0},expireAccessToken:function(){var a=this.getToken();return a?(a.expires_in=0,void this.saveToken(a)):null}});var d="0.5.2";c.OAuth2&&(c.OAuth2.version=d)}),a("ember",[],function(){"use strict";return{"default":Ember}}),window.Ember.OAuth2=b("ember-oauth2")["default"]}(window); \ No newline at end of file diff --git a/lib/ember-oauth2.js b/lib/ember-oauth2.js index 5d237ba..687ee87 100644 --- a/lib/ember-oauth2.js +++ b/lib/ember-oauth2.js @@ -4,7 +4,7 @@ import Ember from 'ember'; * @overview OAuth2 library for Emberjs that stores tokens in the browsers localStorage * @license Licensed under MIT license * See https://raw.github.com/amkirwan/ember-oauth2/master/LICENSE - * @version 0.5.1 + * @version 0.5.2 * * @module ember-oauth2 * @class ember-oauth2 @@ -432,7 +432,7 @@ export default Ember.Object.extend(Ember.Evented, { * @property {String} VERSION * @final */ -var VERSION = "0.5.1"; +var VERSION = "0.5.2"; /** * @method version diff --git a/package.json b/package.json index b70c0ba..19ab1cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ember-oauth2", - "version": "0.5.1", + "version": "0.5.2", "description": "OAuth2 library for Emberjs that stores tokens in the browsers localStorage", "homepage": "https://github.com/amkirwan/ember-ouath2", "main": "dist/ember.oauth2.js", diff --git a/yuidoc.json b/yuidoc.json index 16f16ad..f52462b 100644 --- a/yuidoc.json +++ b/yuidoc.json @@ -1,7 +1,7 @@ { "name": "Ember.OAuth2", "description": "OAuth2 library for Emberjs that stores tokens in the browsers localStorage", - "version": "0.5.1", + "version": "0.5.2", "url": "https://github.com/amkirwan/ember-oauth2", "options": { "exclude": "node_modules,bower_components,scripts",