Skip to content

Commit

Permalink
Ensure refresh token is stored (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikroe authored Nov 29, 2024
1 parent d0c8f7c commit cd6e967
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions bimmer_connected/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,21 +348,20 @@ def main():
except Exception as ex: # pylint: disable=broad-except
sys.stderr.write(f"{type(ex).__name__}: {ex}\n")
sys.exit(1)

if args.disable_oauth_store:
return

args.oauth_store.parent.mkdir(parents=True, exist_ok=True)
args.oauth_store.write_text(
json.dumps(
{
"refresh_token": account.config.authentication.refresh_token,
"gcid": account.config.authentication.gcid,
"access_token": account.config.authentication.access_token,
"session_id": account.config.authentication.session_id,
}
),
)
finally:
# Ensure that the OAuth2 tokens are stored even if an exception occurred
if not args.disable_oauth_store:
args.oauth_store.parent.mkdir(parents=True, exist_ok=True)
args.oauth_store.write_text(
json.dumps(
{
"refresh_token": account.config.authentication.refresh_token,
"gcid": account.config.authentication.gcid,
"access_token": account.config.authentication.access_token,
"session_id": account.config.authentication.session_id,
}
),
)


if __name__ == "__main__":
Expand Down

0 comments on commit cd6e967

Please sign in to comment.