Skip to content

Commit

Permalink
Resolution to GB Authentication issue (#128)
Browse files Browse the repository at this point in the history
* first draft integtration

* Add translation for refresh token

* fix restart issue

* Add Firefox JWT capture example image

* Add configuration details for GB 

For GB a JWT token is needed
  • Loading branch information
ColinRobbins authored Oct 11, 2024
1 parent 65794b1 commit b428dd0
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 14 deletions.
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ A media player component for Home Assistant that controls each LG Horizon Settop

### Parameters

| Parameter | Required | Description |
| ---------- | --------------------- | ----------------------------------- |
| Username | yes | Your provider username |
| Password | yes | Your provider password |
| Provider | yes (default 'Ziggo') | Your Provider |
| Identifier | no (only for Telenet) | Your account identifier (see below) |
| Parameter | Required | Description |
| ------------ | --------------------- | ----------------------------------- |
| Username | yes | Your provider username |
| Password | yes | Your provider password |
| Provider | yes (default 'Ziggo') | Your Provider |
| Identifier | no (only for Telenet) | Your account identifier (see below) |
| Refresh Token | no (only for GB) | A JWT Token (see below) |

## Configuration Telenet multiple accounts

Expand All @@ -78,6 +79,27 @@ After entering your credentials an account selection screen will popup:
![Identifier code](/images/Telenet%20code.png)
- Use that code in the config of your telenet account in HA

## Configuration for Virgin GB
For the Virgin GB integration the Password is not used, instead, you need JWT token.
To get the JWT token you need to download a plugin and then login to your Virgin Box from a web browser as follows.

1. Download a Plug to get access to the tokens:

- For Firefox use [JWT Debugger](https://addons.mozilla.org/en-GB/firefox/addon/jwtio-debugger/)
- For Chrome use [JWT Inspector](https://chromewebstore.google.com/detail/jwt-inspector/jgjihoodklabhdoeffdjofnknfijolgk?hl=en&pli=1)
- For Edge use [JwtToken](https://microsoftedge.microsoft.com/addons/detail/jwttoken/hbppejkakghldbgjeblinppeindhpeoh?hl=en-us)

2. Login to your Virgin box using the web browser
[https://virgintvgo.virginmedia.com/](https://virgintvgo.virginmedia.com/)

3. Open the JWT extension and copy the JWT token.
Firefox example:
![account selection](/images/GB%20Firefox%20JWT.png)
(you need the bit starting `eyJ0...` - make sure you get all of it - its quite long.
_NOTE: Keep this token secure/treat as a password - it gives full access to your virgin box._

4. Paste the JWT token into the Refresh Token parameter

## Service to change channel

```yaml
Expand Down
17 changes: 15 additions & 2 deletions custom_components/lghorizon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .const import (
DOMAIN,
CONF_COUNTRY_CODE,
CONF_REFRESH_TOKEN,
API,
COUNTRY_CODES,
CONF_IDENTIFIER
Expand All @@ -27,7 +28,8 @@
vol.Optional(CONF_COUNTRY_CODE, default="nl"): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_IDENTIFIER):cv.string
vol.Optional(CONF_IDENTIFIER):cv.string,
vol.Optional(CONF_REFRESH_TOKEN):cv.string
}
)
},
Expand All @@ -40,12 +42,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
telenet_identifier = None
if CONF_IDENTIFIER in entry.data:
telenet_identifier = entry.data[CONF_IDENTIFIER]

refresh_token = None
if CONF_REFRESH_TOKEN in entry.data:
refresh_token = entry.data[CONF_REFRESH_TOKEN]

api = LGHorizonApi(
entry.data[CONF_USERNAME],
entry.data[CONF_PASSWORD],
COUNTRY_CODES[entry.data[CONF_COUNTRY_CODE]],
telenet_identifier
telenet_identifier,
refresh_token,
)
await hass.async_add_executor_job(api.connect)
hass.data.setdefault(DOMAIN, {})
Expand All @@ -55,6 +62,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
}
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

if CONF_REFRESH_TOKEN in entry.data:
_LOGGER.info("New JWT stored: %s", api.refresh_token)
new_data = {**entry.data}
new_data[CONF_REFRESH_TOKEN] = api.refresh_token
hass.config_entries.async_update_entry(entry, data=new_data)

return True


Expand Down
12 changes: 9 additions & 3 deletions custom_components/lghorizon/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
import homeassistant.helpers.config_validation as cv

from .const import DOMAIN, CONF_COUNTRY_CODE, COUNTRY_CODES, CONF_IDENTIFIER
from .const import DOMAIN, CONF_COUNTRY_CODE, CONF_REFRESH_TOKEN, COUNTRY_CODES, CONF_IDENTIFIER
from lghorizon import (
LGHorizonApi,
LGHorizonApiUnauthorizedError,
Expand All @@ -29,8 +29,8 @@
),
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_IDENTIFIER):cv.string

vol.Optional(CONF_IDENTIFIER):cv.string,
vol.Optional(CONF_REFRESH_TOKEN):cv.string
}
)

Expand All @@ -42,11 +42,17 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
telenet_identifier = None
if CONF_IDENTIFIER in data:
telenet_identifier = data[CONF_IDENTIFIER]

refresh_token = None
if CONF_REFRESH_TOKEN in data:
refresh_token = data[CONF_REFRESH_TOKEN]

api = LGHorizonApi(
data[CONF_USERNAME],
data[CONF_PASSWORD],
COUNTRY_CODES[data[CONF_COUNTRY_CODE]],
telenet_identifier,
refresh_token,
)
await hass.async_add_executor_job(api.connect)
await hass.async_add_executor_job(api.disconnect)
Expand Down
1 change: 1 addition & 0 deletions custom_components/lghorizon/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
DOMAIN = "lghorizon"
API = "lghorizon_api"
CONF_COUNTRY_CODE = "country_code"
CONF_REFRESH_TOKEN = "refresh_token"
CONF_REMOTE_KEY = "remote_key"
CONF_IDENTIFIER = "identifier"

Expand Down
5 changes: 3 additions & 2 deletions custom_components/lghorizon/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"username": "Username",
"password": "Password",
"country_code": "Provider",
"identifier": "DTV identifier"
"identifier": "DTV identifier",
"refresh_token": "Refresh Token (GB)"
}
}
},
Expand Down Expand Up @@ -68,4 +69,4 @@
}
}
}
}
}
3 changes: 2 additions & 1 deletion custom_components/lghorizon/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"username": "Gebruikersnaam",
"password": "Wachtwoord",
"country_code": "Provider",
"identifier": "DTV identifier"
"identifier": "DTV identifier",
"refresh_token": "Refresh Token (GB)"
}
}
},
Expand Down
Binary file added images/GB Firefox JWT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b428dd0

Please sign in to comment.