Skip to content

Commit

Permalink
[myq] Switch to using oAuth for logins (openhab#11183)
Browse files Browse the repository at this point in the history
* change MyQ binding to use now required oAuth for authentication

Signed-off-by: Dan Cunningham <dan@digitaldan.com>

* Clean up error handling

Signed-off-by: Dan Cunningham <dan@digitaldan.com>

* Cleanup checkstyle errors

Signed-off-by: Dan Cunningham <dan@digitaldan.com>

* missing newline

Signed-off-by: Dan Cunningham <dan@digitaldan.com>

* Remove unused classes

Signed-off-by: Dan Cunningham <dan@digitaldan.com>

* Add token listener

Signed-off-by: Dan Cunningham <dan@digitaldan.com>

* add a redirect limit...just in case

Signed-off-by: Dan Cunningham <dan@digitaldan.com>

* Don't resue the oAuth service if we have been disosed or its closed.  Reduce logging verbosity.

Signed-off-by: Dan Cunningham <dan@digitaldan.com>

* Force login if we get a 401 response

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
  • Loading branch information
digitaldan authored and frederictobiasc committed Oct 26, 2021
1 parent ac1502e commit e900954
Show file tree
Hide file tree
Showing 7 changed files with 420 additions and 151 deletions.
7 changes: 7 additions & 0 deletions bundles/org.openhab.binding.myq/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ https://www.eclipse.org/legal/epl-2.0/.
== Source Code

https://github.com/openhab/openhab-addons

== Third-party Content

jsoup
* License: MIT License
* Project: https://jsoup.org/
* Source: https://github.com/jhy/jsoup
8 changes: 8 additions & 0 deletions bundles/org.openhab.binding.myq/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@

<name>openHAB Add-ons :: Bundles :: MyQ Binding</name>

<dependencies>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<feature name="openhab-binding-myq" description="MyQ Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle dependency="true">mvn:org.jsoup/jsoup/1.8.3</bundle>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.myq/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.openhab.binding.myq.internal.handler.MyQAccountHandler;
import org.openhab.binding.myq.internal.handler.MyQGarageDoorHandler;
import org.openhab.binding.myq.internal.handler.MyQLampHandler;
import org.openhab.core.auth.client.oauth2.OAuthFactory;
import org.openhab.core.io.net.http.HttpClientFactory;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
Expand All @@ -41,10 +42,13 @@
@Component(configurationPid = "binding.myq", service = ThingHandlerFactory.class)
public class MyQHandlerFactory extends BaseThingHandlerFactory {
private final HttpClient httpClient;
private OAuthFactory oAuthFactory;

@Activate
public MyQHandlerFactory(final @Reference HttpClientFactory httpClientFactory) {
public MyQHandlerFactory(final @Reference HttpClientFactory httpClientFactory,
final @Reference OAuthFactory oAuthFactory) {
this.httpClient = httpClientFactory.getCommonHttpClient();
this.oAuthFactory = oAuthFactory;
}

@Override
Expand All @@ -57,7 +61,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();

if (THING_TYPE_ACCOUNT.equals(thingTypeUID)) {
return new MyQAccountHandler((Bridge) thing, httpClient);
return new MyQAccountHandler((Bridge) thing, httpClient, oAuthFactory);
}

if (THING_TYPE_GARAGEDOOR.equals(thingTypeUID)) {
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit e900954

Please sign in to comment.