node-red-web-nodes icon indicating copy to clipboard operation
node-red-web-nodes copied to clipboard

Redirection trouble with raspberry pi

Open fabien14840 opened this issue 10 years ago • 14 comments
trafficstars

HI all,

Here's my trouble,

I'm using the google calendar node on a raspberry pi (I access it via a computer). I wrote an entry in hosts, created an app with the right redirect URI ("node-red-example.com").

But when I try to authenticate with google, after having accepted the permissions, the redirection to the page "Authorised - you can close this window and return to Node-RED" fails (web browser returns a 105 error code), I think it is because the DNS does not know the "node-red-example.com" domain...

It only works if i replace manually the "node-red-example.com" with my raspberry IP in the failing URL, do you have any solution to provide having to do it by myself each time ?

fabien14840 avatar Mar 31 '15 09:03 fabien14840

Having you followed the second part of the instructions:

Please configure the authorized Redirect URIs of your app to include the following url: http://node-red-example.com/google-credentials/auth/callback You will need to edit your hosts file and add an entry for node-red-example.com that points to the actual IP address of your Raspberry Pi.

knolleary avatar Mar 31 '15 18:03 knolleary

Yes i did, because without that, google says that the redirect URI does not match any registered redirect URI

fabien14840 avatar Apr 01 '15 07:04 fabien14840

As well as the bit about editing your hosts file?

knolleary avatar Apr 01 '15 07:04 knolleary

Yes, I created an entry in /etc/hosts first, that associates the name "node-red.example.com" to my Raspberry IP

fabien14840 avatar Apr 01 '15 07:04 fabien14840

So if you made that entry, can you browse to http://node-red.example.com:1880 to see the node-red UI?

knolleary avatar Apr 01 '15 08:04 knolleary

No, i cannot (browser error code : 105), because i access to node-RED on my raspberry by the use of a computer, and the computer only get access to node RED ui with raspberry_IP:1880 or Raspberry_hostname:1880, but only the Raspberry knows what node-red.example.com means, I think that is the reason of the issue

fabien14840 avatar Apr 01 '15 08:04 fabien14840

Yes. You need to edit the hosts file of the computer you are accessing node-red from - as that is the computer that needs to be able to resolve the address.

knolleary avatar Apr 01 '15 08:04 knolleary

Thanks but this solution does not please me that much, because I will need to repeat this step each time I access it from a new computer, and it isn't viable for what I wanna do...

I found an alternative, i am currently trying to authenticate this way :

https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi

fabien14840 avatar Apr 01 '15 09:04 fabien14840

You only need to do this once to complete the authentication process.

@hindessm any comments?

knolleary avatar Apr 01 '15 09:04 knolleary

Once for each computer that provide my Node-RED access, am I wrong ?

fabien14840 avatar Apr 01 '15 09:04 fabien14840

It depends what exactly you are trying to do.

The authentication flow is needed to give Node-RED the necessary access tokens to talk to the google api. You need to set that up once for your flow. So you only need to the host setup on the computer from which you access Node-RED when you are setting up the google node.

knolleary avatar Apr 01 '15 09:04 knolleary

In fact, I try to change this node configuration, my goal is to make the oauth as simple as in the node RED core Twitter Node.

As I imagine this, i get the node, i open config and I click on a authenticate with google button (with google client secret and id already registered in the code) , and it works. But I don't think something as simple is possible if the only solution we have is to configure the computer host in order to make it work...

fabien14840 avatar Apr 01 '15 10:04 fabien14840

The twitter api does not restrict the url you redirect the browser to after authentication; you can specify it as part of the auth flow. This allows us to set a redirect_url dynamically that will work regardless of where node-red is installed and how you are accessing it.

With the google api (as well as foursquare/swarm and a number of others), you have to provide the redirect_url as part of the app configuration andyou must use that redirect_url as part of the flow. We cannot pre-register an app with these apis with a redirect_uri that will Just Work for everyone.

Some of these APIs also explicitly forbid us from registering an app that everyone then uses - they require each user to register their own app.

knolleary avatar Apr 01 '15 10:04 knolleary

But the issue remains, even with your version of the node, so do you think my redirection trouble's unique solution is to configure the computer hosts ? I'll keep searching about the link I mentioned earlier, to see if it solves it.

fabien14840 avatar Apr 01 '15 12:04 fabien14840