admin管理员组文章数量:1432187
I am trying to make use of existing sample code for PassKit to create a JWT token with "Run JavaSript by Zapier". But the Zapier does not recognized the btoa function.
ReferenceError: btoa is not defined
According to this website, this function can be called directly. Any idea?
var b64data = btoa("this is my string to turn into base64");
Below is the code that I have written.
var Zap = {
base64url:function(input){
var base64String = btoa(input); //<--error here
return urlConvertBase64(base64String);
},
urlConvertBase64:function(input){
var output = input.replace(/=+$/, '');
output = output.replace(/\+/g, '-');
output = output.replace(/\//g, '_');
return output;
},
generateJWT:function(key){
var header = {
"alg": "HS256",
"typ": "JWT"
};
var time_now = Math.floor(new Date().getTime()/1000);
var exp = time_now + 30;
var body = {
"exp": exp,
"key": key
};
var token = [];
token[0] = Zap.base64url(JSON.stringify(header));
return body;
}
};
output = [{body: Zap.generateJWT(inputData.Api_key)}]
I am trying to make use of existing sample code for PassKit to create a JWT token with "Run JavaSript by Zapier". But the Zapier does not recognized the btoa function.
ReferenceError: btoa is not defined
According to this website, this function can be called directly. Any idea?
var b64data = btoa("this is my string to turn into base64");
Below is the code that I have written.
var Zap = {
base64url:function(input){
var base64String = btoa(input); //<--error here
return urlConvertBase64(base64String);
},
urlConvertBase64:function(input){
var output = input.replace(/=+$/, '');
output = output.replace(/\+/g, '-');
output = output.replace(/\//g, '_');
return output;
},
generateJWT:function(key){
var header = {
"alg": "HS256",
"typ": "JWT"
};
var time_now = Math.floor(new Date().getTime()/1000);
var exp = time_now + 30;
var body = {
"exp": exp,
"key": key
};
var token = [];
token[0] = Zap.base64url(JSON.stringify(header));
return body;
}
};
output = [{body: Zap.generateJWT(inputData.Api_key)}]
Share
Improve this question
asked Jun 21, 2020 at 15:37
LzcLzc
211 silver badge2 bronze badges
1
- 1 Does this answer your question? Node.js throws "btoa is not defined" error – SMAKSS Commented Jun 21, 2020 at 15:46
1 Answer
Reset to default 7You can use the following:
var b64data = Buffer.from('this is my string to turn into base64').toString('base64');
Node.js doesn't seem to support the atob() and btoa() methods.
本文标签: jwtZapier39s JavaScript function quotbtoaquot is not definedStack Overflow
版权声明:本文标题:jwt - Zapier's JavaScript function "btoa" is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745580275a2664579.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论