Skip to content

add Worker support #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/jwt-token.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var jwt = {};

var JWTInternals = (function() {
var JWTInternals = (function(window) {

// convert a base64url string to hex
var b64urlmap="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
Expand Down Expand Up @@ -89,30 +89,30 @@ var JWTInternals = (function() {
this.key = sjcl.codec.utf8String.toBits(key);
}

HMACAlgorithm.prototype =
HMACAlgorithm.prototype =
{
update: function _update(data)
{
this.data = data;
},

finalize: function _finalize()
{
},

sign: function _sign()
{
var hmac = new sjcl.misc.hmac(this.key, this.hash);
var result = hmac.encrypt(this.data);
return base64urlencode(window.atob(sjcl.codec.base64.fromBits(result)));
},

verify: function _verify(sig)
{
var hmac = new sjcl.misc.hmac(this.key, this.hash);
var result = hmac.encrypt(this.data);
return base64urlencode(window.atob(sjcl.codec.base64.fromBits(result))) == sig;

return base64urlencode(window.atob(sjcl.codec.base64.fromBits(result))) == sig;
}
}

Expand All @@ -123,7 +123,7 @@ var JWTInternals = (function() {
} else if (hash == "sha256") {
this.hash = "sha256";
} else {
throw new NoSuchAlgorithmException("JWT algorithm: " + hash);
throw new NoSuchAlgorithmException("JWT algorithm: " + hash);
}
this.keyPEM = keyPEM;
}
Expand All @@ -135,7 +135,7 @@ var JWTInternals = (function() {
},
finalize: function _finalize()
{

},
sign: function _sign()
{
Expand Down Expand Up @@ -225,7 +225,7 @@ var JWTInternals = (function() {
var signatureValue = algorithm.sign();
return algBytes + "." + jsonBytes + "." + signatureValue;
},

verify: function _verify(key)
{
var header = jsonObj(this.pkAlgorithm);
Expand All @@ -236,9 +236,9 @@ var JWTInternals = (function() {
return algorithm.verify(this.cryptoSegment);
}
}

jwt.WebToken = WebToken;
jwt.WebTokenParser = WebTokenParser;
jwt.base64urlencode = base64urlencode;
jwt.base64urldecode = base64urldecode;
})();
})(this);