openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

[innogy] Issues with Auth Code for innogy SmartHome Binding #3434

Closed whisdol closed 6 years ago

whisdol commented 6 years ago

Expected Behavior

It should be possible to configure the innogy SmartHome Controller.

Current Behavior

When copying/pasting the OAuth URL for the innogy SmartHome portal from the Paper UI, the error message "Invalid redirect URI: https://www.openhab.org/oauth/innogy/innogy-smarthome.html" is displayed.

When using the old URL (https://api.services-smarthome.de/AUTH/authorize?response_type=code&client_id=24635748&redirect_uri=https%3A%2F%2Fwww.ollie.in%2Finnogy-smarthome-token%2F&scope&lang=de-DE), I am able to retrieve an OAuth token. However, when pasting this into the "Authorization Code" field in Paper UI, the configuration fails. When editing it, the authorization code field is empty. It's also just an empty string in the org.eclipse.smarthome.core.thing.Thing.json-file. I see the following error in the log:

2018-04-01 22:21:27.551 [ERROR] [marthome.handler.InnogyBridgeHandler] - Error initializing innogy SmartHome client. org.openhab.binding.innogysmarthome.internal.client.exception.InvalidAuthCodeException: Error fetching access token: {"errorcode":2002,"description":"Invalid token request","messages":["Reason: invalid_request"]} at org.openhab.binding.innogysmarthome.internal.client.InnogyClient.getOAuth2Tokens(InnogyClient.java:242) [226:org.openhab.binding.innogysmarthome:2.3.0.201803311310] at org.openhab.binding.innogysmarthome.internal.client.InnogyClient.initialize(InnogyClient.java:128) [226:org.openhab.binding.innogysmarthome:2.3.0.201803311310] at org.openhab.binding.innogysmarthome.handler.InnogyBridgeHandler$Initializer.run(InnogyBridgeHandler.java:107) [226:org.openhab.binding.innogysmarthome:2.3.0.201803311310] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?] at java.lang.Thread.run(Thread.java:748) [?:?]

Steps to Reproduce (for Bugs)

  1. Install openHAB 2.3.0-SNAPSHOT
  2. Install innogy binding
  3. In Paper UI, go to Inbox > + > innogy SmartHome Binding > add manually > innogy SmartHome Controller (because the Bridge does not show up automatically)
  4. Retrieve OAuth Code from the old (ollie.in)-URL.
  5. Paste OAuth Code into field "Authorization code".
  6. Observe that the added Thing shows:

Status: OFFLINE - CONFIGURATION_ERROR Invalid authcode. Please generate a new one!

  1. Edit the Thing and observe the empty Authorization Code field.

Context

I was excited to try out the new innogy binding to configure my thermostats. However, I'm stuck at the first step: configuring the bridge. As the bridge is not showing up automatically (as it should, according to the docs), maybe I'm doing something fundamentally wrong. I'm also missing an attribute like hostname or IP address in the manual bridge configuration via Paper UI.

Your Environment

kaikreuzer commented 6 years ago

@ollie-dev Could you have a look, please?

ollie-dev commented 6 years ago

I already found the issue. innogy still has the old URLs active and until then it does not work. So I must temporarily switch back to the old URLs.

@kaikreuzer, I can simply provide a temporary binding.jar for the users until innogy changes the URLs - or send you a PR with the old URLs, but will then have to change them back as the new ones are active. Any preferation?

However, a fix will be available tomorrow. Thanks for the detailed report, @whisdol.

ollie-dev commented 6 years ago

I uploaded a new binding-jar with the correct redirect URLs and tested it on an OH 2.3 snapshot installation. Authcode generation works fine with it.

@whisdol, please test it. If the binding throws the following error on startup...

11:27:13.499 [WARN ] [org.apache.felix.fileinstall         ] - Error while starting bundle: file:/Users/oliverkuhl/Downloads/openhab-2.3.0-SNAPSHOT.tar/addons/org.openhab.binding.innogysmarthome-2.3.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.innogysmarthome [229]
  Unresolved requirement: Import-Package: org.eclipse.jdt.annotation; resolution:="optional"
  Unresolved requirement: Import-Package: org.eclipse.jetty.websocket.client

    at org.eclipse.osgi.container.Module.start(Module.java:444) [?:?]
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) [?:?]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [9:org.apache.felix.fileinstall:3.6.4]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [9:org.apache.felix.fileinstall:3.6.4]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:520) [9:org.apache.felix.fileinstall:3.6.4]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [9:org.apache.felix.fileinstall:3.6.4]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [9:org.apache.felix.fileinstall:3.6.4]

...please do a feature:install openhab-httpclient to fix it.

@kaikreuzer, I'll talk to the innogy guys tomorrow about when they can change the URLs and put a link on the new temporary jar in all forums etc.

ollie-dev commented 6 years ago

I found out, that even the new URLs where not correct. :see_no_evil: So I fixed them in PR #3435.

whisdol commented 6 years ago

Great, connecting the SmartHome Bridge works with your jar file. Thank you for the quick response, @ollie-dev!