add unsecured jwt
This commit is contained in:
parent
35f4708d9a
commit
6f86d6ea6c
|
@ -64,6 +64,54 @@
|
||||||
return argsParsed;
|
return argsParsed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
core.utils = {
|
||||||
|
urlSafeBase64ToBase64: function (b64) {
|
||||||
|
// URL-safe Base64 to Base64
|
||||||
|
b64 = b64.replace(/-/g, '+').replace(/_/g, '/');
|
||||||
|
b64 = (b64 + '===').slice(0, b64.length + (b64.length % 4));
|
||||||
|
return b64;
|
||||||
|
}
|
||||||
|
, base64ToUrlSafeBase64: function (b64) {
|
||||||
|
// Base64 to URL-safe Base64
|
||||||
|
b64 = b64.replace(/\+/g, '-').replace(/\//g, '_');
|
||||||
|
b64 = b64.replace(/=+/g, '');
|
||||||
|
return b64;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
core.jwt = {
|
||||||
|
// decode only (no verification)
|
||||||
|
decode: function (str) {
|
||||||
|
|
||||||
|
// 'abc.qrs.xyz'
|
||||||
|
// [ 'abc', 'qrs', 'xyz' ]
|
||||||
|
// [ {}, {}, 'foo' ]
|
||||||
|
// { header: {}, payload: {}, signature: }
|
||||||
|
var parts = str.split(/\./g);
|
||||||
|
var jsons = parts.slice(0, 2).map(function (b64) {
|
||||||
|
var atob = exports.atob || require('atob');
|
||||||
|
return atob(core.utils.urlSafeBase64ToBase64(b64));
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
header: JSON.parse(jsons[0])
|
||||||
|
, payload: JSON.parse(jsons[1])
|
||||||
|
, signature: parts[2]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// encode-only (no signature)
|
||||||
|
, encode: function (parts) {
|
||||||
|
parts.header = parts.header || { alg: 'none', typ: 'jwt' };
|
||||||
|
parts.signature = parts.signature || '';
|
||||||
|
var result = [
|
||||||
|
core.utils.base64ToUrlSafeBase64(JSON.stringify(parts.header, null))
|
||||||
|
, core.utils.base64ToUrlSafeBase64(JSON.stringify(parts.payload, null))
|
||||||
|
, parts.signature
|
||||||
|
].join('.');
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
core.authorizationCode = function (/*directive, scope, redirectUri, clientId*/) {
|
core.authorizationCode = function (/*directive, scope, redirectUri, clientId*/) {
|
||||||
//
|
//
|
||||||
// Example Authorization Code Request
|
// Example Authorization Code Request
|
||||||
|
|
Loading…
Reference in New Issue