我想为Paw生成Json Web Tokens创建一个DynamicValue插件。完整的来源可以在这里找到:https://github.com/choffmeister/Paw-JsonWebTokenDynamicValue
相关文件:
// JsonWebTokenDynamicValue.js
import jsrsasign from 'jsrsasign';
@registerDynamicValueClass
class JsonWebTokenDynamicValue {
static identifier = 'de.choffmeister.PawExtensions.JsonWebTokenDynamicValue';
static title = 'Json Web Token';
static help = 'https://github.com/choffmeister/Paw-JsonWebTokenDynamicValue';
static inputs = [
DynamicValueInput('signatureSecret', 'Secret', 'SecureValue'),
DynamicValueInput('signatureSecretIsBase64', 'Secret is Base64', 'Checkbox'),
DynamicValueInput('payload', 'Payload', 'JSON')
];
evaluate() {
console.log(JSON.stringify(this.payload, null, 2));
console.log(JSON.stringify(this.signatureSecretIsBase64, null, 2));
const now = Math.floor((new Date()).getTime() / 1000);
const header = {
typ: 'JWT',
alg: 'HS256'
};
const payload = {
...this.payload,
exp: now + (60 * 60 * 24 * 7),
iat: now
};
const secret = this.signatureSecretIsBase64
? {b64: jsrsasign.b64utob64(this.signatureSecret)}
: this.signatureSecret;
return jsrsasign.jws.JWS.sign(null, header, payload, secret);
}
}
它在GUI中的外观:
我搜索了https://luckymarmot.com/paw/doc/extensions/create-dynamic-value,周围的文档以及我在网上找到的所有插件示例,但我还有两个无法解决的问题:
Checkbox
的DynamicValueInput时,输入字段不可见(请参见屏幕截图)。我得到一个值(空字符串),但只是看不到它。如何显示复选框?当使用类型为JSON
的DynamicValueInput时,在JSON中使用的动态值(参见屏幕截图)没有得到解决,而是我得到了一种描述对象(字符串化),这个动态值是什么。记录this.payload
对象如下所示:
{
"foo": "[{\"data\":{\"environmentVariable\":\"2925ABDA-8AAC-440B-B2CA-DA216CD37A09\"},\"identifier\":\"com.luckymarmot.EnvironmentVariableDynamicValue\"}]"
}
也许值得注意:当使用KeyValueList
类型的DynamicInputValue时,内部动态值会被正确解析。我怎样才能使用JSON
类型来实现此目的?
答案 0 :(得分:0)
此问题已在Paw 2.3.3中得到解决,而Thekwasti的扩展实际上已在此处发布:https://luckymarmot.com/paw/extensions/JsonWebTokenDynamicValue