Skip to content

Commit

Permalink
Implement OAuth2 authorization
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
  • Loading branch information
jlaur committed Apr 4, 2023
1 parent b8c4198 commit f00020f
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 399 deletions.
14 changes: 12 additions & 2 deletions bundles/org.openhab.binding.boschindego/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ Currently the binding supports _**indego**_ mowers as a thing type with these

| Parameter | Description | Default |
|--------------------|-------------------------------------------------------------------|---------|
| username | Username for the Bosch Indego account | |
| password | Password for the Bosch Indego account | |
| refresh | The number of seconds between refreshing device state when idle | 180 |
| stateActiveRefresh | The number of seconds between refreshing device state when active | 30 |
| cuttingTimeRefresh | The number of minutes between refreshing last/next cutting time | 60 |

### Authorization

To authorize, please follow these steps:

- In your browser, go to the [Bosch SingleKey ID login page](https://prodindego.b2clogin.com/prodindego.onmicrosoft.com/b2c_1a_signup_signin/oauth2/v2.0/authorize?redirect_uri=com.bosch.indegoconnect://login&client_id=65bb8c9d-1070-4fb4-aa95-853618acc876&response_type=code&scope=openid%20offline_access%20https://prodindego.onmicrosoft.com/indego-mobile-api/Indego.Mower.User).
- Select "Bosch ID", enter your e-mail address and password and clock "Log-in".
- In your browser, open Developer Tools.
- With developer tools showing in the right, go to [Bosch SingleKey ID login page](https://prodindego.b2clogin.com/prodindego.onmicrosoft.com/b2c_1a_signup_signin/oauth2/v2.0/authorize?redirect_uri=com.bosch.indegoconnect://login&client_id=65bb8c9d-1070-4fb4-aa95-853618acc876&response_type=code&scope=openid%20offline_access%20https://prodindego.onmicrosoft.com/indego-mobile-api/Indego.Mower.User) again.
- "Please wait..." should now be displayed.
- Find the `authresp` and copy the code: `com.bosch.indegoconnect://login/?code=<copy this>`
- Use the openHAB console to authorize with this code: `openhab:boschindego authorize <paste code>`

## Channels

| Channel | Item Type | Description | Writeable |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ public class BoschIndegoBindingConstants {
public static final String GARDEN_MAP = "gardenMap";

public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_INDEGO);

// Bosch SingleKey ID OAuth2
private static final String BSK_BASE_URI = "https://prodindego.b2clogin.com/prodindego.onmicrosoft.com/b2c_1a_signup_signin/oauth2/v2.0/";
public static final String BSK_CLIENT_ID = "65bb8c9d-1070-4fb4-aa95-853618acc876";
public static final String BSK_AUTH_URI = BSK_BASE_URI + "authorize";
public static final String BSK_TOKEN_URI = BSK_BASE_URI + "token";
public static final String BSK_REDIRECT_URI = "com.bosch.indegoconnect://login";
public static final String BSK_SCOPE = "openid offline_access https://prodindego.onmicrosoft.com/indego-mobile-api/Indego.Mower.User";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.openhab.binding.boschindego.internal.handler.BoschIndegoHandler;
import org.openhab.core.auth.client.oauth2.OAuthFactory;
import org.openhab.core.i18n.LocaleProvider;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.i18n.TranslationProvider;
Expand All @@ -37,21 +38,25 @@
* handlers.
*
* @author Jonas Fleck - Initial contribution
* @author Jacob Laursen - Replaced authorization by OAuth2
*/
@NonNullByDefault
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.boschindego")
public class BoschIndegoHandlerFactory extends BaseThingHandlerFactory {

private final HttpClient httpClient;
private final OAuthFactory oAuthFactory;
private final BoschIndegoTranslationProvider translationProvider;
private final TimeZoneProvider timeZoneProvider;

@Activate
public BoschIndegoHandlerFactory(@Reference HttpClientFactory httpClientFactory,
final @Reference TranslationProvider i18nProvider, final @Reference LocaleProvider localeProvider,
final @Reference TimeZoneProvider timeZoneProvider, ComponentContext componentContext) {
final @Reference OAuthFactory oAuthFactory, final @Reference TranslationProvider i18nProvider,
final @Reference LocaleProvider localeProvider, final @Reference TimeZoneProvider timeZoneProvider,
ComponentContext componentContext) {
super.activate(componentContext);
this.httpClient = httpClientFactory.getCommonHttpClient();
this.oAuthFactory = oAuthFactory;
this.translationProvider = new BoschIndegoTranslationProvider(i18nProvider, localeProvider);
this.timeZoneProvider = timeZoneProvider;
}
Expand All @@ -66,7 +71,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();

if (THING_TYPE_INDEGO.equals(thingTypeUID)) {
return new BoschIndegoHandler(thing, httpClient, translationProvider, timeZoneProvider);
return new BoschIndegoHandler(thing, httpClient, oAuthFactory, translationProvider, timeZoneProvider);
}

return null;
Expand Down
Loading

0 comments on commit f00020f

Please sign in to comment.