Links
Snippets
OAuth token management
- This is a workaround to use multiple oauth2 identities.
- appcfg.py offers either password auth or oauth2.
- If you use oauth2, you're resricted to just 1 identity –
the file storing the information is hardcoded to
~/.appcfg_oauth2_tokens. (Ref: appengine_rpc_httplib2.py: HttpRpcServerOauth2) - You can use
--no_cookiesto avoid using that single hardcoded path. - But now you have to provide the refresh token as the
--oauth2_refresh_tokenparam. (I would much rather that it support the--passinparam as used by the password option instead of having it show up in the argv.) Sigh.
Here's one approach toward managing it.
import keyring # Store OAuth token for later use. def save_oauth2_refresh_token(email, oauth2_refresh_token): keyring.set_password( "OAuth2 Refresh Token: " + email + ": AppengineLauncher", email, oauth2_refresh_token) # Sample call. import getpass save_oauth2_refresh_token("email@....", getpass.getpass()) def get_oauth2_refresh_token(email): return keyring.get_password( "OAuth2 Refresh Token: " + email + ": AppengineLauncher", email)
And wrap the call to appcfg.py using
get_oauth2_refresh_token to pass in the
--oauth2_refresh_token param (remember to also pass in
--oauth2, --no_cookies and --noauth_local_webserver)