Skip to content

Commit

Permalink
Release: 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
amkirwan committed Oct 20, 2015
1 parent f80461b commit 9561cb1
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ JavaScript library for using OAuth 2.0 Implicit Grant flow (Client-Side Flow) or

This creates an OAuth 2.0 Ember object class for handling authentication with OAuth 2.0 providers.

Current Version: **[1.0.0](https://github.com/amkirwan/ember-oauth2/releases/tag/v1.0.0)**
Current Version: **[1.0.1](https://github.com/amkirwan/ember-oauth2/releases/tag/v1.0.1)**

The EmberCli addon [EmberTokenAuth](https://github.com/amkirwan/ember-token-auth) demonstrates how to use Ember-OAuth2 library for authentication.

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-oauth2",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/amkirwan/ember-oauth2",
"authors": [
"Anthony Kirwan <amkirwan@gmail.com>"
Expand Down
33 changes: 18 additions & 15 deletions dist/ember-oauth2.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 1.0.0
* @version 1.0.1
*
* @module ember-oauth2
* @class ember-oauth2
Expand Down Expand Up @@ -97,7 +97,6 @@ define("ember-oauth2",

/**
* @event redirect
* @param {function} The function that handles the redirect.
*/
this.on('redirect', this.handleRedirect);
},
Expand Down Expand Up @@ -174,7 +173,7 @@ define("ember-oauth2",
if (!this.get('redirectUri')) throw new Error('No redirect uri given.');
var authorizeUri = this.authUri();
this.clearStates();
this.saveState(this.get('state'), this.requestObj());
this.saveState(this.requestObj());
return this.openWindow(authorizeUri);
},

Expand Down Expand Up @@ -246,7 +245,7 @@ define("ember-oauth2",
var params = this.parseCallback(hash);

if (this.authSuccess(params)) {
var stateObj = this.getState(params.state);
var stateObj = this.getState();
this.checkState(stateObj);

if (this.get('responseType') === "token") {
Expand All @@ -270,10 +269,15 @@ define("ember-oauth2",
*
* @method checkState
* @param {Object} stateObj The object returned from localStorage
* @return {Boolean} Will return true if the states match otherwise it will throw an Error
*/
checkState: function(stateObj) {
if (!stateObj) throw new Error("Could not find state.");
if (stateObj.state !== this.get('state')) throw new Error("State returned from the server did not match the local saved state.");
if (stateObj.state === this.get('state')) {
return true;
} else {
throw new Error("State returned from the server did not match the local saved state.");
}
},

/**
Expand Down Expand Up @@ -302,26 +306,25 @@ define("ember-oauth2",

/**
* @method saveState
* @param {String} state The state uuid
* @param {Object} requestObj Properties of the request state to save in localStorage
*/
saveState: function(state, requestObj) {
saveState: function(requestObj) {
window.localStorage.setItem(this.stateKeyName(), JSON.stringify(requestObj));
},

/**
* Return the saved state and remove it from the localStoage.
* Return the saved state object and remove it from the localStoage.
*
* @method getState
* @param {String} state The state uuid to retreive from localStorage
* @return {Object} Properties of the request state
*/
getState: function(state) {
var keyName = state || this.stateKeyName();
var obj = JSON.parse(window.localStorage.getItem(keyName));
this.removeState();
getState: function() {
var stateObj = JSON.parse(window.localStorage.getItem(this.stateKeyName()));
if (!stateObj) return null;

this.removeState(this.stateKeyName());

return obj;
return stateObj;
},

/**
Expand Down Expand Up @@ -459,7 +462,7 @@ define("ember-oauth2",
* @property {String} VERSION
* @final
*/
var VERSION = "1.0.0";
var VERSION = "1.0.1";

/**
* @method version
Expand Down
4 changes: 2 additions & 2 deletions dist/ember-oauth2.amd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 18 additions & 15 deletions dist/ember-oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 1.0.0
* @version 1.0.1
*
* @module ember-oauth2
* @class ember-oauth2
Expand Down Expand Up @@ -93,7 +93,6 @@ export default Ember.Object.extend(Ember.Evented, {

/**
* @event redirect
* @param {function} The function that handles the redirect.
*/
this.on('redirect', this.handleRedirect);
},
Expand Down Expand Up @@ -170,7 +169,7 @@ export default Ember.Object.extend(Ember.Evented, {
if (!this.get('redirectUri')) throw new Error('No redirect uri given.');
var authorizeUri = this.authUri();
this.clearStates();
this.saveState(this.get('state'), this.requestObj());
this.saveState(this.requestObj());
return this.openWindow(authorizeUri);
},

Expand Down Expand Up @@ -242,7 +241,7 @@ export default Ember.Object.extend(Ember.Evented, {
var params = this.parseCallback(hash);

if (this.authSuccess(params)) {
var stateObj = this.getState(params.state);
var stateObj = this.getState();
this.checkState(stateObj);

if (this.get('responseType') === "token") {
Expand All @@ -266,10 +265,15 @@ export default Ember.Object.extend(Ember.Evented, {
*
* @method checkState
* @param {Object} stateObj The object returned from localStorage
* @return {Boolean} Will return true if the states match otherwise it will throw an Error
*/
checkState: function(stateObj) {
if (!stateObj) throw new Error("Could not find state.");
if (stateObj.state !== this.get('state')) throw new Error("State returned from the server did not match the local saved state.");
if (stateObj.state === this.get('state')) {
return true;
} else {
throw new Error("State returned from the server did not match the local saved state.");
}
},

/**
Expand Down Expand Up @@ -298,26 +302,25 @@ export default Ember.Object.extend(Ember.Evented, {

/**
* @method saveState
* @param {String} state The state uuid
* @param {Object} requestObj Properties of the request state to save in localStorage
*/
saveState: function(state, requestObj) {
saveState: function(requestObj) {
window.localStorage.setItem(this.stateKeyName(), JSON.stringify(requestObj));
},

/**
* Return the saved state and remove it from the localStoage.
* Return the saved state object and remove it from the localStoage.
*
* @method getState
* @param {String} state The state uuid to retreive from localStorage
* @return {Object} Properties of the request state
*/
getState: function(state) {
var keyName = state || this.stateKeyName();
var obj = JSON.parse(window.localStorage.getItem(keyName));
this.removeState();
getState: function() {
var stateObj = JSON.parse(window.localStorage.getItem(this.stateKeyName()));
if (!stateObj) return null;

this.removeState(this.stateKeyName());

return obj;
return stateObj;
},

/**
Expand Down Expand Up @@ -455,7 +458,7 @@ export default Ember.Object.extend(Ember.Evented, {
* @property {String} VERSION
* @final
*/
var VERSION = "1.0.0";
var VERSION = "1.0.1";

/**
* @method version
Expand Down
4 changes: 2 additions & 2 deletions lib/ember-oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 1.0.0
* @version 1.0.1
*
* @module ember-oauth2
* @class ember-oauth2
Expand Down Expand Up @@ -458,7 +458,7 @@ export default Ember.Object.extend(Ember.Evented, {
* @property {String} VERSION
* @final
*/
var VERSION = "1.0.0";
var VERSION = "1.0.1";

/**
* @method version
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-oauth2",
"version": "1.0.0",
"version": "1.0.1",
"description": "OAuth2 library for Emberjs that stores tokens in the browsers localStorage",
"homepage": "https://github.com/amkirwan/ember-ouath2",
"main": "dist/ember.oauth2.js",
Expand Down
2 changes: 1 addition & 1 deletion yuidoc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Ember.OAuth2",
"description": "OAuth2 library for Emberjs that stores tokens in the browsers localStorage",
"version": "1.0.0",
"version": "1.0.1",
"url": "https://github.com/amkirwan/ember-oauth2",
"options": {
"exclude": "node_modules,bower_components,scripts",
Expand Down

0 comments on commit 9561cb1

Please sign in to comment.