Skip to content

Instantly share code, notes, and snippets.

@julianpitt
Created January 26, 2026 02:47
Show Gist options
  • Select an option

  • Save julianpitt/94774e74d36a46f9ec10ddce13cfd423 to your computer and use it in GitHub Desktop.

Select an option

Save julianpitt/94774e74d36a46f9ec10ddce13cfd423 to your computer and use it in GitHub Desktop.
Obtaining a Goolge account Master token (alternative method)

Obtaining a Goolge account Master token (alternative method)

This is a detailed version of the Alternative flow for gpsoauth I'm using uv for my python project but you can use whatever python package manager you like.

This python 3 script generates a Master token which can be used for a number of applications. I'm using mine for the Home Assistant custom integration.

I've created this gist because I was unable to get the following methods working with 2fa enabled on my google account:

Try these methods first, then the following as an alternative.

Token types

It's important to know the different types of tokens and when they expire:

  • OAuth token - Is in the form oauth2_4/*** and is very short lived. Needs oauth sign form for an application.
  • Master token - Is in the form aas_et/*** and is long lived. Needs Google username and password.
  • Access token - Is in the form ya29.*** and lasts for an hour. Needs Master token to generate.

Steps

  1. Create a new project directory on your local machine and initialise a new python project. uv init && uv venv && source .venv/bin/activate for uv.
  2. Add the dependency for gpsoauth. uv add gpsoauth for uv.
  3. Copy the file get_master_token.py from this gist to your local machine and replace the email address with your email address.
  4. Go to https://accounts.google.com/EmbeddedSetup
  5. Log into your Google Account and follow any additional login steps.
  6. Click on "I agree" when prompted. The page may show a loading screen forever; ignore it and move on to the next step.
  7. Obtain the value of the oauth_token cookie. Follow one of the two methods detailed in this readme if you are unsure how.
  8. Replace the oauth token you receive from the step above in the token value in the get_master_token.py script.
  9. Run the get_master_token.py script. uv run get_master_token.py for uv.

Troubleshooting

  • Make sure you have replace the values for your email address and token in the script.
  • The oauth token is only valid for a single use and expires quickly. Make sure you use it as soon as possible.
import json
import gpsoauth
email = '{Your gmail address}' # insert your gmail address / google username here
android_id = '0123456789abcdef' # leave this as is
token = 'oauth2_4/XXXXXXXXXX' # insert the oauth_token value here
master_response = gpsoauth.exchange_token(email, token, android_id)
print(f"Full response for debugging:")
print(json.dumps(master_response))
master_token = master_response['Token']
print(f"\nMaster token {master_token}")
MIT License
Copyright (c) 2020 Rithvik Vibhu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment