I’m trying to set the parameters of an instantiated node dynamically. I understand that this requires the ability to get the node details, make the changes and then redeploy it. I have a good example of how to do this, but it won’t work on a system with security enabled.
I think the key is being able to “set the Authorization header to pass the token”. I don’t see a way to do that in the http request node.
Then too, you have to get the token before you can pass it and I don’t know how to do that either.
Thanks,
Bob
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/kCkeyZHu-IY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/f05385de-8d85-4239-bb2d-86e5b270ed44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Bob,
The mechanism for obtaining an access token is documented here: http://nodered.org/docs/api/admin/oauth
The info sidebar for the http request node describes how to set additional http headers using the msg.headers property you pass the node.
Nick
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/!%26!AAAAAAAAAAAYAAAAAAAAAPilthT1PgxCu8%2BnGAeNZvbCgAAAEAAAAIt8OEb4Fd1KpYf9FFcOfu0BAAAAAA%3D%3D%40sculley.net.
Yeah, I think I get it, but I can’t seem to get it to work.
I have this in the function node:
msg.headers= {
'client_id': 'node-red-admin',
'grant_type': 'password',
'scope': '*',
'username': 'admin',
'password': 'password'}
return msg;
And this in the http request node (entered in the template):
Method : POST
URL: http://localhost:1880/auth/token
The response id 401 Unauthorized.
This line (from the documentation) works at the command line:
curl http://localhost:1880/auth/token --data 'client_id=node-red-admin&grant_type=password&scope=*&username=admin&password=password'
What am I doing wrong?
Bob
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/CAF%3Dvhqc%3DdNRDDHeiFpC4sto6QduKme3yScn4YZekRRpW3WdEkA%40mail.gmail.com.
Ok, I have changed the http request to work off of the message properties.
I’m using this:
msg.method="POST";
return msg;
The response is still “Unauthorized”
Here is the complete response:
2/25/2017 7:27:06 AMnode: 8af1c4a3.712518msg : Object
{ _msgid: "b5605d48.4a9fa", topic: "", payload: "Unauthorized", method: "POST", url: "http://localhost:1880/auth/tok…" … }object
_msgid: "b5605d48.4a9fa"
topic: ""
payload: "Unauthorized"
method: "POST"
statusCode: 401
headers: object
x-powered-by: "Express"
date: "Sat, 25 Feb 2017 15:27:03 GMT"
connection: "close"
content-length: "12"
responseUrl: "http://localhost:1880/auth/token?client_id=node-red-admin&grant_type=password&scope=*&username=admin&password=password"
I also tried it with GET. Same response.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/2f03b311-04f2-4306-998e-d51844193a11%40googlegroups.com.
OK, I finally figured it out.
The data doesn’t go as query parameters, but as POST form data.
Here is the full setup for anyone that might be interested:
msg.method="POST";
msg.url="http://localhost:1880/auth/token";
msg.payload= {'client_id': 'node-red-admin',
'grant_type': 'password',
'scope': '*',
'username': 'admin',
'password': 'password'}
msg.headers={
'Accept': '*/*',
'Content-Type': 'application/x-www-form-urlencoded'
}
return msg;
It would be great to include this in the documentation.
Bob
From: node...@googlegroups.com [mailto:node...@googlegroups.com] On Behalf Of Ben Hardill
Sent: Saturday, February 25, 2017 3:57 AM
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/2f03b311-04f2-4306-998e-d51844193a11%40googlegroups.com.