Google Home local authentication token extraction
Python package to extract Google Home devices local authentication tokens from Google servers. These local authentication tokens are needed to control Google Home devices (See @rithvikvibhu's Google Home (2.0) API).
How it works
glocaltokens gets three kinds of tokens, each from the one before:
- Master token: starts with
aas_et/and is long lived. You get it once with your Google username and password, or with a browser sign-in (see "If logging in with a password fails" below). - Access token: lives 1 hour. glocaltokens gets a new one from the master token when it expires.
- Local authentication tokens: one per device, used to send requests to that device. They only live about 1 day, so you will need to get new ones regularly.
Store the master token, not your password: with the master token alone, glocaltokens can get the other tokens whenever you need them.
Installation
glocaltokens requires Python 3.12 or newer.
It also requires gpsoauth 3.0.1 or newer. If you use Google Keep Sync in the same Home Assistant installation, update it to version 1.2.0 or newer before updating glocaltokens. Google Keep Sync 1.1.0 pins gpsoauth to 2.0.0, which conflicts with this version of glocaltokens.
To fill in the IP address and port of each device, glocaltokens looks for your devices on the local network.
That needs the discovery extra, which installs zeroconf.
Using uv:
$ uv add "glocaltokens[discovery]"
Using pip:
$ pip install "glocaltokens[discovery]"
You can install glocaltokens without the extra if you turn discovery off, for example because you only need the tokens or give the device addresses yourself
(see Finding devices on your network).
Quickstart
from glocaltokens.client import GLocalAuthenticationTokens
client = GLocalAuthenticationTokens(
username="<YOUR_GOOGLE_USERNAME>", password="<YOUR_GOOGLE_PASSWORD>"
)
# Get master token, then store it (see "Authentication" below)
print("[*] Master token", client.get_master_token())
# Get Google device local authentication tokens (live about 1 day)
print(client.get_google_devices_json())
See example/get_tokens.py for a complete script that reads your credentials from environment variables.
Authentication
Logging in with a password
Log in with the password only once, then store the master token and use it instead. If you log in too often, Google will disconnect your Android devices and other weird things will happen.
If your Google account uses 2-Step Verification, create an app password and use it instead of your regular password.
Reusing the master token
Never store the user's password nor username in plain text, if storage is necessary, generate a master token and store it. The master token gives access to the Google account, so protect it like a password.
from glocaltokens.client import GLocalAuthenticationTokens
# Using Google username and password first, and only once
client = GLocalAuthenticationTokens(
username="<YOUR_GOOGLE_USERNAME>", password="<YOUR_GOOGLE_PASSWORD>"
)
master_token = client.get_master_token()
"""Now store master_token somewhere"""
# Later, use the stored master token instead of the username and password
client = GLocalAuthenticationTokens(master_token=master_token)
If logging in with a password fails
Logging in with a password does not work for every account. If get_master_token() raises AuthenticationError (see Errors),
or your account uses a passkey, sign in with a browser instead and let glocaltokens exchange that sign-in for a master token.
This uses gpsoauth's alternative flow:
- Open https://accounts.google.com/EmbeddedSetup and sign in to your Google account.
- Click "I agree" when asked. The page may keep loading forever; you can ignore that.
- Copy the value of the
oauth_tokencookie, for example from the cookies list in your browser's developer tools. - Pass it to the client, then get the master token and store it:
client = GLocalAuthenticationTokens(oauth_token="<YOUR_OAUTH_TOKEN_COOKIE>")
master_token = client.get_master_token()
email = client.get_email()
Treat the oauth_token cookie like a password. If the exchange fails, sign in again to get a new cookie.
After that, use the stored master token as shown above.
The client trims leading and trailing whitespace from both tokens. A master token
must start with aas_et/, have at least 200 characters including the prefix, and
contain only visible ASCII characters with no spaces. A master token can pass
this local check and still be refused by Google.
Finding the account of a master token
A master token doesn't say which Google account it belongs to. get_email() returns the account's email address,
or None if Google doesn't give one. If the client got the master token itself, get_email() returns the address Google sent with it.
Otherwise it asks Google, and returns the address only if Google has verified it:
client = GLocalAuthenticationTokens(master_token="<YOUR_MASTER_TOKEN>")
print(client.get_email())
Getting device tokens
get_google_devices() returns a list of Device objects, and get_google_devices_json() returns the same list as a JSON string:
[
{
"device_id": "...",
"device_name": "Living Room speaker",
"network_device": {
"ip": "192.168.1.10",
"port": 8009
},
"hardware": "Google Nest Mini",
"cloud_device_id": "...",
"home_id": "...",
"home_name": "Home",
"local_auth_token": "..."
}
]
device_name is the name in the Google Home app. A speaker pair is found on the network at its leading speaker, but keeps the pair's name.
The JSON doesn't include the name a device announces on the network. For a Device object found there, it is in network_device.name.
cloud_device_id is the ID Google gives the device, or null if Google gives none.
To match a device at an address you know, request https://<ip>:8443/setup/eureka_info?params=device_info and compare cloud_device_id with device_info.cloud_device_id in the response, ignoring case.
The device's certificate is self-signed, so turn off certificate verification for this request.
home_id and home_name are the ID and name of the home the device is in, in the Google Home app.
If your account has several homes, pass a home_id to get only that home's devices.
To list every home, including homes without devices, use get_home_graph(): each entry of its homes has an id and a display_name.
The client caches the tokens it gets from Google for 24 hours. Pass force_homegraph_reload=True to fetch new ones sooner.
Selecting models
By default you get all devices with valid local authentication tokens, without filtering by model. To get only some models, pass a list of model names as models_list.
The names are the hardware values in the output above.
GOOGLE_HOME_MODELS in const.py lists some common models:
- Google Home
- Google Home Mini
- Google Nest Mini
- Lenovo Smart Clock
from glocaltokens.const import GOOGLE_HOME_MODELS
google_devices = client.get_google_devices_json(GOOGLE_HOME_MODELS)
# Or your own list
google_devices = client.get_google_devices_json(["Google Home", "Google Nest Mini"])
The list is not complete. If your model is missing, use your own list, or add it to GOOGLE_HOME_MODELS with a pull request.
Finding devices on your network
To fill in ip and port, glocaltokens looks for devices on your local network with mDNS (zeroconf),
so it must run on the same network as your devices. Devices it does not find have null for both.
If discovery does not work on your network, turn it off and give the IPv4 address of each device, using its name in the Google Home app:
google_devices = client.get_google_devices_json(
disable_discovery=True,
addresses={"Living Room speaker": "192.168.1.10"},
)
Only IPv4 addresses are supported. If any entry is not a valid IPv4 address, the device methods raise ValueError.
Discovery needs the discovery extra (see Installation). Without it, the device methods raise ModuleNotFoundError unless you turn discovery off as above,
and importing glocaltokens.scanner, which has the discovery code, raises it too.
NetworkDevice, the type of Device.network_device, can be imported from glocaltokens.types without the extra.
Options
Both get_google_devices() and get_google_devices_json() accept these arguments:
| Argument | Default | Description |
|---|---|---|
models_list |
None |
Only return these models. None returns all devices with valid local authentication tokens. |
disable_discovery |
False |
Do not search the local network for device IP addresses and ports. |
addresses |
None |
{"device name": "IPv4 address"}, used when discovery is disabled or finds nothing. |
zeroconf_instance |
None |
An existing zeroconf.Zeroconf instance to use for discovery. glocaltokens leaves it open. |
force_homegraph_reload |
False |
Fetch new tokens from Google even if the cached ones are less than 24 hours old. |
discovery_timeout |
3 |
How long to search the local network, in seconds. |
home_id |
None |
Only return the devices of the home with this ID. None returns the devices of every home. |
The event loop of zeroconf_instance must be running, and can't be the calling thread's (see Errors).
get_google_devices_json() also accepts indent for the JSON output (default 2).
async_get_google_devices() and async_get_google_devices_and_home_graph() take these options with clearer names (see Async device options).
Using asyncio
The methods that ask Google have async counterparts: async_get_master_token(), async_get_access_token(), async_get_email(),
async_get_home_graph() and async_get_google_devices().
They return the same results and raise the same glocaltokens errors, and they wait for Google and the network without blocking your event loop.
With discovery on, the first device call imports glocaltokens' discovery code and zeroconf on your event loop, unless they're already imported:
import glocaltokens.scanner when your application starts to avoid that short delay.
Two methods have no async counterpart. Instead of get_homegraph(), which merges every home into one, use async_get_home_graph().
Instead of get_google_devices_json(), use json.dumps([device.as_dict() for device in devices]).
To use your application's aiohttp session, pass it as session. glocaltokens never closes it. Without one, each request uses a new session that is closed afterwards.
import aiohttp
from glocaltokens.client import GLocalAuthenticationTokens
async def main() -> None:
async with aiohttp.ClientSession() as session:
client = GLocalAuthenticationTokens(
master_token="<YOUR_MASTER_TOKEN>", session=session
)
devices, home_graph = await client.async_get_google_devices_and_home_graph()
async_get_google_devices_and_home_graph() returns the device list and the home graph it came from, with every device of every home,
including those the list leaves out, such as devices without a local authentication token.
Use it rather than reading the home graph separately: another call can replace the cached home graph while discovery runs.
The sync and async methods share the cached tokens and home graph. Don't use one client from several threads at once.
How your session affects the requests to Google:
- The home graph, which has the device tokens, comes over gRPC, not through your session. The other requests go through it.
- They check Google's certificate even if your session doesn't check certificates. Like the sync sign-in requests, they trust the system's certificate
authorities and those in the bundle
requestsuses, which is certifi's unless theREQUESTS_CA_BUNDLEorCURL_CA_BUNDLEenvironment variable names another file or directory. glocaltokens reads these variables when it's imported. If it can't load that bundle, the async requests raiseOSError, asrequestsdoes. - Your session's middlewares apply to them. An exception a middleware raises reaches your code.
- Your session's
raise_for_statussetting doesn't apply to them: glocaltokens handles each answer itself, as described in Errors. - Cookies in your session's cookie jar for Google's addresses are sent with them, and cookies Google sets are kept in the jar.
- Your session's default headers are sent with them, except those glocaltokens sets itself, such as
User-Agent. - They use your session's proxy settings. A session that glocaltokens creates follows the
HTTP_PROXY,HTTPS_PROXYandNO_PROXYenvironment variables, but aiohttp ignores proxy addresses there that start withhttps://. - Don't pass a session with default
authcredentials: they would be sent to Google.
Async device options
async_get_google_devices() and async_get_google_devices_and_home_graph() take the options of get_google_devices() by name only,
with clearer names for three of them:
| Option | Default | Sync option | Description |
|---|---|---|---|
models |
None |
models_list |
Only return these models. None returns all devices with valid local authentication tokens. |
home_id |
None |
home_id |
Only return the devices of the home with this ID. None returns the devices of every home. |
discover |
True |
disable_discovery |
Search the local network for device IP addresses and ports. discover=False is disable_discovery=True. |
zeroconf_instance |
None |
zeroconf_instance |
A zeroconf.Zeroconf that runs on your event loop, such as Home Assistant's shared instance or an AsyncZeroconf's zeroconf. |
discovery_timeout |
3 |
discovery_timeout |
How long to search the local network, in seconds. |
addresses |
None |
addresses |
{"device name": "IPv4 address"}, used when discovery is off or finds nothing. |
reload_home_graph |
False |
force_homegraph_reload |
Fetch a new home graph, with new device tokens, from Google even if the cached one is less than 24 hours old. |
Without a zeroconf_instance, glocaltokens creates its own for discovery and closes it afterwards. It leaves yours open.
Troubleshooting
If you get no devices or an error, turn on debug logs for glocaltokens to see each step:
import logging
logging.basicConfig()
logging.getLogger("glocaltokens").setLevel(logging.DEBUG)
glocaltokens doesn't set log levels, so it follows your application's logging configuration.
The client's verbose argument and the logging_level argument of discover_devices() are deprecated: they only emit a DeprecationWarning.
glocaltokens masks your password and tokens in its logs, but they also include Google's responses to failed requests, so check them before you share them, for example in an issue.
Errors
The token and device methods raise an error when they can't get what you asked for. They don't return None or an empty list instead.
An account without devices is not an error: get_google_devices() returns an empty list and get_google_devices_json() returns "[]".
get_email() returns None if Google gives no email address, including when Google refuses the request for it.
glocaltokens raises these errors when Google gives no tokens or devices. They are in glocaltokens.exceptions and are subclasses of GLocalTokensError, so you can catch both at once:
AuthenticationError: Google gave no master or access token, returned a malformed master token, the username and password are too long together to log in with, or the client has no master token and neither anoauth_tokennor a username and password to get one with. This usually means you need to sign in again (see Authentication). Itserrorattribute can contain a reason from Google, such asBadAuthenticationorNeedsBrowser. If Google gives no master token, the library keeps the reason when it is a string and setserrortoNoneotherwise. If Google returns a malformed master token,erroris alwaysNone.get_master_token(),get_access_token(),get_email()and the device methods raise it.HomegraphError: Google didn't return your devices. The device methods raise it. Itscodeattribute is the gRPC status code of the failed request as agrpc.StatusCode. For example,UNAVAILABLEandDEADLINE_EXCEEDEDmean Google is unavailable or did not reply within 10 seconds: try again later.UNAUTHENTICATEDmeans Google kept rejecting the access token, even after glocaltokens got a new one. If that keeps happening, sign in again.
These errors from the libraries glocaltokens uses also reach your code:
requests.RequestExceptionwhen a request to Google fails, for example without an internet connection or when Google does not reply within 10 seconds. A request for a token also raises it when Google answers that you should try later (HTTP 5xx or 429).get_master_token(),get_access_token(),get_email()and the device methods raise it. Try again later.OSErrorwhen network discovery cannot start, for example because no network interface is available. Passdisable_discovery=True(discover=Falseto the async methods) if you do not need IP addresses and ports.zeroconf.EventLoopBlockedfrom the sync device methods when the event loop of yourzeroconf_instanceis blocked or stopped during discovery: they raise it 10 seconds afterdiscovery_timeout. Discovery stops once that loop runs again; until then, it stays on the loop. If that loop cancels discovery instead, for example as it shuts down, they raiseconcurrent.futures.CancelledError.OSErrorwhen the certificate bundle thatREQUESTS_CA_BUNDLEorCURL_CA_BUNDLEnames can't be loaded. Each request for a token or the email address raises it; the home graph request, which uses gRPC's own certificates, doesn't. Correct or unset the variable.
A mistake in your call raises ValueError. This includes creating the client without credentials,
passing a token that is neither a string nor None, supplying a nonempty master token that fails the local format check,
or passing addresses that aren't a dictionary of IPv4 addresses to the device methods.
The async device methods also raise it for a zeroconf_instance that runs on another event loop, before any request.
The sync device methods raise RuntimeError before any request for a zeroconf_instance that runs on the calling thread's event loop,
as discovery runs on that loop, which the call would block. They don't return the devices with only your addresses instead.
On that loop, use the async methods, or run the whole sync call in an executor, as Home Assistant's async_add_executor_job() does.
They also raise RuntimeError before any request if the event loop of your zeroconf_instance isn't running, for example after you closed a Zeroconf that runs its own loop.
Without the discovery extra, the device methods raise ModuleNotFoundError before any request if discovery is on.
Install glocaltokens[discovery], or pass disable_discovery=True (discover=False to the async methods).
The async methods raise aiohttp's errors instead of requests errors:
aiohttp.ClientResponseErrorwhen Google answers a request for a token that you should try later (HTTP 5xx or 429). Itsstatusattribute is the HTTP status.aiohttp.ClientErrororTimeoutErrorwhen a request to Google fails, for example without an internet connection or when Google does not reply within 10 seconds.async_get_email()raisesjson.JSONDecodeError, oraiohttp.ContentTypeError, if Google's answer with the email address isn't JSON.get_email()raisesrequests.RequestExceptionfor it.
This example tells "sign in again" from "try again later". To keep it simple, it treats every HomegraphError as temporary;
check its code to also handle UNAUTHENTICATED that keeps happening:
import requests
from glocaltokens.client import GLocalAuthenticationTokens
from glocaltokens.exceptions import AuthenticationError, HomegraphError
client = GLocalAuthenticationTokens(master_token="<YOUR_MASTER_TOKEN>")
try:
devices = client.get_google_devices()
except AuthenticationError as err:
print(f"Sign in again to get a new master token: {err}")
except (HomegraphError, requests.RequestException) as err:
print(f"Try again later: {err}")
Contributing
See Contributing guidelines. This is an open-source project and all contributions are highly welcomed.
Credits
Much credit goes to @rithvikvibhu for doing most of the heavy work like finding a way to extract master and access tokens (See the gist here).
Also, thank you very much to the guys at pychromecast which provided the code required to scan devices in the network.
Metadata
Release files for glocaltokens 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| glocaltokens-2.1.1.tar.gz | 209.2 kB | With provenance | Details for glocaltokens-2.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| glocaltokens-2.1.1-py3-none-any.whl | Python 3 | none | any | Details for glocaltokens-2.1.1-py3-none-any.whl |
Total release size: 240.3 kB
Release files / glocaltokens-2.1.1.tar.gz
| Download URL | glocaltokens-2.1.1.tar.gz |
|---|---|
| Size | 209.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
125d8358e49d798bbd063f13272c06c79f4fef0b1693f9b201152106820e7f71
|
|
BLAKE2b-256 checksum How to use checksums |
5c457157be6673b182ef72da93010c2b5791ed0a39c9ed8856e75eb6d9e7b030
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logRelease files / glocaltokens-2.1.1-py3-none-any.whl
| Download URL | glocaltokens-2.1.1-py3-none-any.whl |
|---|---|
| Size | 31.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da2c21ebc3ecfbfc3a42f8b42c19f313dfbb6d8b10d251eae33a35bc52389851
|
|
BLAKE2b-256 checksum How to use checksums |
39e19bac6f1b2a46fe1f53acc7ed5cae5b3f47ba8217acb853d6939e9a4dc66c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for glocaltokens 2.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for glocaltokens-2.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.