browser localStorage does not contain access_token (normally under key: 'hassTokens')
Home Assistant Android app version(s): 2024.10.3-full Android version(s): 12 Device model(s): Samsung Galaxy s10 Home Assistant version: 2024.10.3 Last working Home Assistant release (if known): N/A Description of problem, include YAML if issue is related to notifications: I have a widget which is client-side only, and it gets the access_token (and refresh_token) from localStorage. I then use this token to make authenticated requests. This works great through the browser or an app like fully kiosk and wallpanel.
On the Companion App (android), however, localStorage does not contain the access_token (normally in key: ‘hassTokens’). window.__tokenCache is also undefined. I verified this via Chrome USB Debugging. There are other keys related to home assistant in localStorage, but not the hassTokens key and no other key that contains the access_token.
Companion App Logs:
Screenshot or video of problem:
Additional information:
this is probably a frontend issue, dont think the app has control over this at all.
In case you weren't already aware, auth for apps actually works somewhat differently which may explain your issues.
Also, while we try not to break compatibility scraping data from cookies/storage is very much unsupported territory for the app. Maybe the frontend people can help you, but I'm going to close this for now in here.
FWIW, i was able to get ahold of the access token like this (I havent cleaned this up, but you get the idea). The data in this response doesnt include a refreshToken; i havent tested, but im hoping that this data is periodically updated by the app.
const getTokenFromHassConnection = () => {
let hassConnection = window.hassConnection || window.parent.hassConnection;
if(hassConnection) {
return hassConnection.then((config) => {
if (config?.auth?.data?.access_token) {
return `access_token=${config.auth.data.access_token}`;
}
return `access_token=`;
})
.catch((err) => {
console.log(`error getting access token from HASS Connection: ${err}`);
return `access_token=`;
})
}
return Promise.resolve(`access_token=`);
}