stormpath-js
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "stormpath.js", | ||
"description": "A browser-ready javascript library for Stormpath", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"license": "Apache 2.0", | ||
@@ -6,0 +6,0 @@ "main": "dist/stormpath.js", |
@@ -75,3 +75,12 @@ # Contributing | ||
The release task will do the following tasks: | ||
You can begin the release task with this grunt command: | ||
````bash | ||
grunt release | ||
```` | ||
You will be prompted for the type of release (path, minor, major). | ||
After answering, the task will do the following: | ||
* Build the project and place the ouput in the `dist` folder | ||
@@ -84,21 +93,12 @@ * Bump the verion numbers in these files: | ||
* README.md | ||
* Commit those files with a version message | ||
* Tag the repo with the new version | ||
* Push this new commit and tag to origin/master | ||
Once you are POSITIVE that everything is ready for | ||
release you may run the release task: | ||
It will then ask if you would like to commit the files and push them to origin/master with a new tag. | ||
While at this prompt you may use your git tool of choice to reivew the changes that have been made. | ||
At this point you may answer yes to have the files committed and pushed, or answer no to end the task. | ||
If you answer no, it is epexcted that you will manually commit, push and tag the changes. | ||
````bash | ||
grunt release | ||
```` | ||
The task will not automatically publish this proejct to NPM, you must do that manually. | ||
Once that task completes you should publish the package to Npm: | ||
````bash | ||
npm publish | ||
```` | ||
Bower is updated automatically by the tags that were pushed by the release task | ||
Finally, you should push the new version to the Stormpath CDN |
/* | ||
Stormpath.js v0.1.0 | ||
Stormpath.js v0.2.0 | ||
(c) 2014 Stormpath, Inc. http://stormpath.com | ||
@@ -63,3 +63,4 @@ License: Apache 2.0 | ||
{ | ||
body: data | ||
body: data, | ||
withCredentials: true | ||
}, | ||
@@ -79,3 +80,4 @@ callback || utils.noop | ||
{ | ||
body: data | ||
body: data, | ||
withCredentials: true | ||
}, | ||
@@ -157,2 +159,3 @@ callback || utils.noop | ||
self.xhr.onreadystatechange = self.onLoad.bind(self); | ||
self.xhr.onerror = self.onerror.bind(self); | ||
self.xhr.open(method,url); | ||
@@ -162,4 +165,6 @@ if(options.withCredentials){ | ||
} | ||
self.xhr.setRequestHeader('Authorization', 'Bearer '+self.options.authToken); | ||
self.xhr.setRequestHeader('Content-Type','application/json'); | ||
self.xhr.send(JSON.stringify(options.body)); | ||
self.opened = false; | ||
self.done = false; | ||
@@ -172,9 +177,3 @@ return self; | ||
var s = self.xhr.readyState; | ||
if(s === XHR.OPENED && !self.opened) { | ||
self.xhr.setRequestHeader('Authorization', 'Bearer '+self.options.authToken); | ||
self.xhr.setRequestHeader('Content-Type','application/json'); | ||
self.opened = true; | ||
} | ||
if(s === XHR.DONE && !self.done) { | ||
try{ | ||
@@ -196,2 +195,7 @@ var headers = self.responseHeaders = self.getHeadersObject(); | ||
}; | ||
Request.prototype.onerror = function onerror() { | ||
var self = this; | ||
self.done = true; | ||
self.cb(new Error('Unknown XHR Error')); | ||
}; | ||
Request.prototype.getHeadersObject = function getHeadersObject() { | ||
@@ -225,3 +229,3 @@ var self = this; | ||
self.authToken = newToken; | ||
if(!self.authToken){ | ||
if(!err && !self.authToken){ | ||
self.terminated = true; | ||
@@ -228,0 +232,0 @@ } |
/* | ||
Stormpath.js v0.1.0 | ||
Stormpath.js v0.2.0 | ||
(c) 2014 Stormpath, Inc. http://stormpath.com | ||
License: Apache 2.0 | ||
*/ | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.Stormpath=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){function c(a,b){var c="object"==typeof a?a:{},g="function"==typeof a?a:b||e.noop,h=this;if(h.jwt=c.token||h._getToken(),!h.jwt)return void setTimeout(function(){g(new Error("jwt not found as url query parameter"))},1);try{h.jwtPayload=JSON.parse(f.atob(h.jwt.split(".")[1])),h.appHref=h.jwtPayload.app_href,h.sptoken=h.jwtPayload.sp_token||null,h.baseurl=h.appHref.match("^.+//([^/]+)/")[0]}catch(i){return void setTimeout(function(){g(i)},1)}h.requestExecutor=c.requestExecutor||new d(h.jwt),h.requestExecutor.execute("GET",h.appHref+"?expand=idSiteModel",function(a,b){g(a,a?null:b.idSiteModel)})}var d=a("./request-executor"),e=a("./utils"),f=e.base64;c.prototype._getToken=function(){return decodeURIComponent((window.location.href.match(/jwt=(.+)/)||[])[1]||"")},c.prototype.login=function(a,b){var c,d=this,f="object"==typeof a?a:null;if(!f)throw new Error("must provide an object");if(f.providerData)c=f;else{if(!f.login)throw new Error("unsupported credentials object");c={type:"basic",value:e.base64.btoa(f.login+":"+f.password)}}d.requestExecutor.execute("POST",d.appHref+"/loginAttempts",{body:c},b||e.noop)},c.prototype.register=function(a,b){if("object"!=typeof a)throw new Error("client.register() must be called with a data object");var c=this;c.requestExecutor.execute("POST",c.appHref+"/accounts",{body:a},b||e.noop)},c.prototype.verifyEmailToken=function(a){if("function"!=typeof a)throw new Error("client.verifyEmailToken() takes a function as it's only argument");var b=this;b.requestExecutor.execute("POST",b.baseurl+"/v1/accounts/emailVerificationTokens/"+b.sptoken,a)},c.prototype.verifyPasswordResetToken=function(a){if("function"!=typeof a)throw new Error("client.verifyPasswordResetToken() takes a function as it's only argument");var b=this;b.requestExecutor.execute("GET",b.appHref+"/passwordResetTokens/"+b.sptoken,a)},c.prototype.setAccountPassword=function(a,b,c){if(!a||!a.href)throw new Error("invalid pwTokenVerification");if(!b)throw new Error("must supply new password as second argument to client.setAccountPassword()");var d=this;d.requestExecutor.execute("POST",a.href,{body:{password:b}},c||e.noop)},c.prototype.sendPasswordResetEmail=function(a,b){if("string"!=typeof a)throw new Error("sendPasswordResetEmail must be called with an email or username as the first argument");var c=this;c.requestExecutor.execute("POST",c.appHref+"/passwordResetTokens",{body:{email:a}},b||e.noop)},b.exports=c},{"./request-executor":3,"./utils":4}],2:[function(a,b){b.exports={Client:a("./client")}},{"./client":1}],3:[function(a,b){function c(a,b,c,d){var e=this;return e.cb=d,e.options=c,e.xhr=new XMLHttpRequest,e.xhr.onreadystatechange=e.onLoad.bind(e),e.xhr.open(a,b),c.withCredentials&&(e.xhr.withCredentials=c.withCredentials),e.xhr.send(JSON.stringify(c.body)),e.opened=!1,e.done=!1,e}function d(a){this.authToken=a,this.terminated=!1}var e=a("./utils");c.prototype.onLoad=function(){var a=this,b=XMLHttpRequest,c=a.xhr.readyState;if(c!==b.OPENED||a.opened||(a.xhr.setRequestHeader("Authorization","Bearer "+a.options.authToken),a.xhr.setRequestHeader("Content-Type","application/json"),a.opened=!0),c===b.DONE&&!a.done)try{var d=a.responseHeaders=a.getHeadersObject(),e="string"==typeof a.xhr.responseText&&""!==a.xhr.responseText?JSON.parse(a.xhr.responseText):{},f=a.xhr.status,g=((d.Authorization||"").match(/Bearer (.*)$/i)||[])[1]||"";a.cb(400>f?null:e,g,a,400>f?e:null),a.done=!0}catch(h){a.cb(h)}},c.prototype.getHeadersObject=function(){var a=this,b=a.xhr.getAllResponseHeaders().trim().split("\n");return b.reduce(function(a,b){var c=b.split(": ");return a[c[0]]=c[1].trim(),a},{})},d.prototype.execute=function(a,b,d,f){var g=this;if(g.terminated)return f(new Error("Request executor terminated, you must initiate a new flow from the service provider"));var h="object"==typeof d?d:{body:null};h.authToken=g.authToken;var i="function"==typeof d?d:f||e.noop,j=new c(a,b,h,function(a,b,c,d){if(g.authToken=b,g.authToken||(g.terminated=!0),a)return i(a);var e=c.responseHeaders["Stormpath-SSO-Redirect-Location"];e&&(d.redirectUrl=e),i(a,d)});return j},b.exports=d},{"./utils":4}],4:[function(a,b){b.exports={base64:a("base64"),noop:function(){}}},{base64:5}],5:[function(a,b,c){!function(){function a(a){this.message=a}var b="undefined"!=typeof c?c:this,d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a.prototype=new Error,a.prototype.name="InvalidCharacterError",b.btoa||(b.btoa=function(b){for(var c,e,f=String(b),g=0,h=d,i="";f.charAt(0|g)||(h="=",g%1);i+=h.charAt(63&c>>8-g%1*8)){if(e=f.charCodeAt(g+=.75),e>255)throw new a("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");c=c<<8|e}return i}),b.atob||(b.atob=function(b){var c=String(b).replace(/=+$/,"");if(c.length%4==1)throw new a("'atob' failed: The string to be decoded is not correctly encoded.");for(var e,f,g=0,h=0,i="";f=c.charAt(h++);~f&&(e=g%4?64*e+f:f,g++%4)?i+=String.fromCharCode(255&e>>(-2*g&6)):0)f=d.indexOf(f);return i})}()},{}]},{},[2])(2)}); | ||
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.Stormpath=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){function c(a,b){var c="object"==typeof a?a:{},g="function"==typeof a?a:b||e.noop,h=this;if(h.jwt=c.token||h._getToken(),!h.jwt)return void setTimeout(function(){g(new Error("jwt not found as url query parameter"))},1);try{h.jwtPayload=JSON.parse(f.atob(h.jwt.split(".")[1])),h.appHref=h.jwtPayload.app_href,h.sptoken=h.jwtPayload.sp_token||null,h.baseurl=h.appHref.match("^.+//([^/]+)/")[0]}catch(i){return void setTimeout(function(){g(i)},1)}h.requestExecutor=c.requestExecutor||new d(h.jwt),h.requestExecutor.execute("GET",h.appHref+"?expand=idSiteModel",function(a,b){g(a,a?null:b.idSiteModel)})}var d=a("./request-executor"),e=a("./utils"),f=e.base64;c.prototype._getToken=function(){return decodeURIComponent((window.location.href.match(/jwt=(.+)/)||[])[1]||"")},c.prototype.login=function(a,b){var c,d=this,f="object"==typeof a?a:null;if(!f)throw new Error("must provide an object");if(f.providerData)c=f;else{if(!f.login)throw new Error("unsupported credentials object");c={type:"basic",value:e.base64.btoa(f.login+":"+f.password)}}d.requestExecutor.execute("POST",d.appHref+"/loginAttempts",{body:c,withCredentials:!0},b||e.noop)},c.prototype.register=function(a,b){if("object"!=typeof a)throw new Error("client.register() must be called with a data object");var c=this;c.requestExecutor.execute("POST",c.appHref+"/accounts",{body:a,withCredentials:!0},b||e.noop)},c.prototype.verifyEmailToken=function(a){if("function"!=typeof a)throw new Error("client.verifyEmailToken() takes a function as it's only argument");var b=this;b.requestExecutor.execute("POST",b.baseurl+"/v1/accounts/emailVerificationTokens/"+b.sptoken,a)},c.prototype.verifyPasswordResetToken=function(a){if("function"!=typeof a)throw new Error("client.verifyPasswordResetToken() takes a function as it's only argument");var b=this;b.requestExecutor.execute("GET",b.appHref+"/passwordResetTokens/"+b.sptoken,a)},c.prototype.setAccountPassword=function(a,b,c){if(!a||!a.href)throw new Error("invalid pwTokenVerification");if(!b)throw new Error("must supply new password as second argument to client.setAccountPassword()");var d=this;d.requestExecutor.execute("POST",a.href,{body:{password:b}},c||e.noop)},c.prototype.sendPasswordResetEmail=function(a,b){if("string"!=typeof a)throw new Error("sendPasswordResetEmail must be called with an email or username as the first argument");var c=this;c.requestExecutor.execute("POST",c.appHref+"/passwordResetTokens",{body:{email:a}},b||e.noop)},b.exports=c},{"./request-executor":3,"./utils":4}],2:[function(a,b){b.exports={Client:a("./client")}},{"./client":1}],3:[function(a,b){function c(a,b,c,d){var e=this;return e.cb=d,e.options=c,e.xhr=new XMLHttpRequest,e.xhr.onreadystatechange=e.onLoad.bind(e),e.xhr.onerror=e.onerror.bind(e),e.xhr.open(a,b),c.withCredentials&&(e.xhr.withCredentials=c.withCredentials),e.xhr.setRequestHeader("Authorization","Bearer "+e.options.authToken),e.xhr.setRequestHeader("Content-Type","application/json"),e.xhr.send(JSON.stringify(c.body)),e.done=!1,e}function d(a){this.authToken=a,this.terminated=!1}var e=a("./utils");c.prototype.onLoad=function(){var a=this,b=XMLHttpRequest,c=a.xhr.readyState;if(c===b.DONE&&!a.done)try{var d=a.responseHeaders=a.getHeadersObject(),e="string"==typeof a.xhr.responseText&&""!==a.xhr.responseText?JSON.parse(a.xhr.responseText):{},f=a.xhr.status,g=((d.Authorization||"").match(/Bearer (.*)$/i)||[])[1]||"";a.cb(400>f?null:e,g,a,400>f?e:null),a.done=!0}catch(h){a.cb(h)}},c.prototype.onerror=function(){var a=this;a.done=!0,a.cb(new Error("Unknown XHR Error"))},c.prototype.getHeadersObject=function(){var a=this,b=a.xhr.getAllResponseHeaders().trim().split("\n");return b.reduce(function(a,b){var c=b.split(": ");return a[c[0]]=c[1].trim(),a},{})},d.prototype.execute=function(a,b,d,f){var g=this;if(g.terminated)return f(new Error("Request executor terminated, you must initiate a new flow from the service provider"));var h="object"==typeof d?d:{body:null};h.authToken=g.authToken;var i="function"==typeof d?d:f||e.noop,j=new c(a,b,h,function(a,b,c,d){if(g.authToken=b,a||g.authToken||(g.terminated=!0),a)return i(a);var e=c.responseHeaders["Stormpath-SSO-Redirect-Location"];e&&(d.redirectUrl=e),i(a,d)});return j},b.exports=d},{"./utils":4}],4:[function(a,b){b.exports={base64:a("base64"),noop:function(){}}},{base64:5}],5:[function(a,b,c){!function(){function a(a){this.message=a}var b="undefined"!=typeof c?c:this,d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";a.prototype=new Error,a.prototype.name="InvalidCharacterError",b.btoa||(b.btoa=function(b){for(var c,e,f=String(b),g=0,h=d,i="";f.charAt(0|g)||(h="=",g%1);i+=h.charAt(63&c>>8-g%1*8)){if(e=f.charCodeAt(g+=.75),e>255)throw new a("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");c=c<<8|e}return i}),b.atob||(b.atob=function(b){var c=String(b).replace(/=+$/,"");if(c.length%4==1)throw new a("'atob' failed: The string to be decoded is not correctly encoded.");for(var e,f,g=0,h=0,i="";f=c.charAt(h++);~f&&(e=g%4?64*e+f:f,g++%4)?i+=String.fromCharCode(255&e>>(-2*g&6)):0)f=d.indexOf(f);return i})}()},{}]},{},[2])(2)}); |
@@ -40,3 +40,3 @@ 'use strict'; | ||
process: function(src) { | ||
return src.replace(/[0-9]\.[0-9]\.[0-9]/g, grunt.config.get('pkg.version')); | ||
return src.replace(/\/[0-9]\.[0-9]\.[0-9]\//g, grunt.config.get('pkg.version')); | ||
}, | ||
@@ -110,3 +110,3 @@ }, | ||
config: 'release.confirmed', | ||
message: 'Ready for release? This will version the files and push them to master', | ||
message: 'The files have been prepared, would you like to commit them and push to origin/master with a new tag?', | ||
type: 'confirm', | ||
@@ -117,2 +117,28 @@ default: false | ||
} | ||
}, | ||
semverType: { | ||
options:{ | ||
questions: [{ | ||
config: 'release.semverType', | ||
type: 'list', | ||
message: 'What semver type is this release?', | ||
choices:[ | ||
{ | ||
name: 'Patch (x.x.V)', | ||
value: 'patch', | ||
checked: true | ||
}, | ||
{ | ||
name: 'Minor (x.V.x)', | ||
value: 'minor', | ||
checked: false | ||
}, | ||
{ | ||
name: 'Major (V.x.x)', | ||
value: 'major', | ||
checked: false | ||
} | ||
] | ||
}] | ||
} | ||
} | ||
@@ -130,11 +156,14 @@ } | ||
grunt.registerTask('release', function (target){ | ||
grunt.registerTask('_release', function (){ | ||
var t = grunt.config.get('release.confirmed'); | ||
if(!t){ | ||
grunt.registerTask('release', function (){ | ||
grunt.registerTask('_commit', function (){ | ||
if(!grunt.config.get('release.confirmed')){ | ||
grunt.fail.warn('You have aborted the release task.'); | ||
} | ||
grunt.task.run(['bump-only:'+(target||'patch'),'dist','bump-commit']); | ||
grunt.task.run(['bump-commit']); | ||
}); | ||
grunt.task.run(['prompt:release','_release']); | ||
grunt.registerTask('_release', function (){ | ||
var t = grunt.config.get('release.semverType'); | ||
grunt.task.run(['bump-only:'+(t),'dist','prompt:release','_commit']); | ||
}); | ||
grunt.task.run(['prompt:semverType','_release']); | ||
}); | ||
@@ -141,0 +170,0 @@ |
@@ -57,3 +57,4 @@ var RequestExecutor = require('./request-executor'); | ||
{ | ||
body: data | ||
body: data, | ||
withCredentials: true | ||
}, | ||
@@ -73,3 +74,4 @@ callback || utils.noop | ||
{ | ||
body: data | ||
body: data, | ||
withCredentials: true | ||
}, | ||
@@ -76,0 +78,0 @@ callback || utils.noop |
@@ -9,2 +9,3 @@ var utils = require('./utils'); | ||
self.xhr.onreadystatechange = self.onLoad.bind(self); | ||
self.xhr.onerror = self.onerror.bind(self); | ||
self.xhr.open(method,url); | ||
@@ -14,4 +15,6 @@ if(options.withCredentials){ | ||
} | ||
self.xhr.setRequestHeader('Authorization', 'Bearer '+self.options.authToken); | ||
self.xhr.setRequestHeader('Content-Type','application/json'); | ||
self.xhr.send(JSON.stringify(options.body)); | ||
self.opened = false; | ||
self.done = false; | ||
@@ -24,9 +27,3 @@ return self; | ||
var s = self.xhr.readyState; | ||
if(s === XHR.OPENED && !self.opened) { | ||
self.xhr.setRequestHeader('Authorization', 'Bearer '+self.options.authToken); | ||
self.xhr.setRequestHeader('Content-Type','application/json'); | ||
self.opened = true; | ||
} | ||
if(s === XHR.DONE && !self.done) { | ||
try{ | ||
@@ -48,2 +45,7 @@ var headers = self.responseHeaders = self.getHeadersObject(); | ||
}; | ||
Request.prototype.onerror = function onerror() { | ||
var self = this; | ||
self.done = true; | ||
self.cb(new Error('Unknown XHR Error')); | ||
}; | ||
Request.prototype.getHeadersObject = function getHeadersObject() { | ||
@@ -77,3 +79,3 @@ var self = this; | ||
self.authToken = newToken; | ||
if(!self.authToken){ | ||
if(!err && !self.authToken){ | ||
self.terminated = true; | ||
@@ -80,0 +82,0 @@ } |
{ | ||
"name": "stormpath-js", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A browser-ready javascript library for Stormpath. Use this library if you are building your own ID Site from scratch. Additional features may be added in the future.", | ||
@@ -20,2 +20,3 @@ "main": "lib/index.js", | ||
"license": "Apache-2.0", | ||
"keywords": ["stormpath"], | ||
"devDependencies": { | ||
@@ -22,0 +23,0 @@ "browserify": "^4.2.0", |
@@ -240,2 +240,13 @@ # Stormpath.js - BETA | ||
# Changelog | ||
### 0.2.0 | ||
Support for Single-Sign-On (SSO) | ||
### 0.1.0 | ||
First release! This release includes all the methods that you need to | ||
build your own ID Site | ||
# Contributing | ||
@@ -242,0 +253,0 @@ |
@@ -10,2 +10,3 @@ 'use strict'; | ||
res.setHeader('Access-Control-Allow-Headers','Accept, Authorization, Content-Type'); | ||
res.setHeader('Access-Control-Allow-Credentials','true'); | ||
if(req.method==='OPTIONS'){ | ||
@@ -12,0 +13,0 @@ res.statusCode = 204; |
@@ -116,3 +116,3 @@ 'use strict'; | ||
it('should post that data to the api',function(){ | ||
assert.deepEqual(calledWith[0],{body:input}); | ||
assert.deepEqual(calledWith[0].body,input); | ||
}); | ||
@@ -134,3 +134,3 @@ }); | ||
it('should post base64 encode the data and post it to the api',function(){ | ||
assert.deepEqual(calledWith[1],{body:{type:'basic',value:data.encoded}}); | ||
assert.deepEqual(calledWith[1].body,{type:'basic',value:data.encoded}); | ||
}); | ||
@@ -180,3 +180,3 @@ }); | ||
expect(calledWith[0][1]).to.have.string('/accounts'); | ||
assert.deepEqual(calledWith[0][2],{body:data}); | ||
assert.deepEqual(calledWith[0][2].body,data); | ||
}); | ||
@@ -183,0 +183,0 @@ }); |
72794
1309
255