added auth node to verify/decode idToken JWT sent from clients
This commit is contained in:
56
auth/verify-idtoken.html
Normal file
56
auth/verify-idtoken.html
Normal file
@ -0,0 +1,56 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('verify-idtoken',{
|
||||
|
||||
category: 'firebase-admin',
|
||||
color: '#a6bbcf',
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
cred: {value: "", type: 'firebase-config'}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
icon: "firebase-auth.png",
|
||||
label: function() {
|
||||
return this.name||"verify-idtoken";
|
||||
},
|
||||
|
||||
oneditsave: function() {
|
||||
let type = $('#apitype-select').val()
|
||||
console.log('type is set to '+type)
|
||||
|
||||
},
|
||||
|
||||
oneditprepare: function() {
|
||||
$('#apitype-select').change(function () {
|
||||
$("#node-input-apitype").val($(this).find('option:selected').val())
|
||||
});
|
||||
$("#apitype-select").val($("#node-input-apitype").val())
|
||||
$('#apitype-select').trigger('change');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="verify-idtoken">
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="node-input-cred"><i class="icon-tag"></i> Credentials</label>
|
||||
<input type="text" id="node-input-cred" placeholder="Name">
|
||||
</div>
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="verify-idtoken">
|
||||
<p>A node that wraps the verify-idtoken API from the firebase-admin SDK</p>
|
||||
Reoslved a given JWT token in payload as a user object for the current project (that the configured credentials is pointing to)
|
||||
<p>
|
||||
input: {"payload": "......JWT......"}
|
||||
<p>
|
||||
output: The decoded User object for the given JWT idToken
|
||||
|
||||
</script>
|
||||
41
auth/verify-idtoken.js
Normal file
41
auth/verify-idtoken.js
Normal file
@ -0,0 +1,41 @@
|
||||
// "eyJhbGciOiJSUzI1NiIsImtpZCI6Ijc0NGY2MGU5ZmI1MTVhMmEwMWMxMWViZWIyMjg3MTI4NjA1NDA3MTEiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiYXpwIjoiOTczNDA4MDM4MzUwLWI2aGNoN3NvamliNmkxNjZtN3BtOWtmcDNvaHJoMzRrLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiYXVkIjoiOTczNDA4MDM4MzUwLWI2aGNoN3NvamliNmkxNjZtN3BtOWtmcDNvaHJoMzRrLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwic3ViIjoiMTA5ODI2MDk5NjU1NTU2Mjk4ODI0IiwiZW1haWwiOiJwc3ZlbnNzb25AZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImF0X2hhc2giOiJmVkpiSWRzMFFuVlBWbm50VUtoSmFnIiwiaWF0IjoxNTk2OTY1OTMxLCJleHAiOjE1OTY5Njk1MzF9.Rq8bsj-RlcMdVjk2UuJrUykyJcRcaTRohQD788lCigIVxLedxIJ5rZRndRVzSTUmX2n_sgCdtiFLN2w16KHy5v2053fNXvlyEuR4t1fctt_LU-OygLGW4qeSPEWonu7zBmhy2aaJBHnx0NzqRbCYewm0zVrI_BEgju-OvJAlH5pud9Ycs7o7d6NaJsJp0JW3bEcz0bgETA2jWlYIR3ZeQSRxYcjwTZ2OhbocMEWYVFVoTF8n0PVlFe21cZs3RfA2KWfuVvwvrB2BGku6rkVANoT8UJKkhLP81NipgPzIowui72O5pbCCm5senj5D_VMh74NmptHSLAKTGHv36EzzPA"
|
||||
|
||||
|
||||
module.exports = function (RED) {
|
||||
function FirebaseAdmin(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
var node = this;
|
||||
|
||||
if (config.cred) {
|
||||
let c = RED.nodes.getNode(config.cred)
|
||||
this.admin = c.admin
|
||||
}
|
||||
|
||||
node.on('input', function (msg) {
|
||||
if (msg && msg.payload) {
|
||||
console.log('verify-idtoken got input')
|
||||
console.dir(msg)
|
||||
const idtoken = msg.payload.idtoken
|
||||
try {
|
||||
this.admin.auth().verifyIdToken(idtoken)
|
||||
.then(function (decodedToken) {
|
||||
console.log('verify-idtoken got result:')
|
||||
console.dir(decodedToken)
|
||||
this.status({ fill: "green", shape: "ring", text: '' });
|
||||
node.send({ payload: decodedToken })
|
||||
}.bind(this)).catch(function (error) {
|
||||
console.log('verify-idtoken caught an exception!')
|
||||
console.dir(error)
|
||||
this.status({ fill: "red", shape: "ring", text: error.errorInfo.message });
|
||||
}.bind(this));
|
||||
} catch (ex) {
|
||||
this.status({ fill: "red", shape: "ring", text: ex.code });
|
||||
}
|
||||
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
|
||||
}
|
||||
RED.nodes.registerType("verify-idtoken", FirebaseAdmin);
|
||||
}
|
||||
Reference in New Issue
Block a user