fix(login): persist fresh credentials and drop the legacy auth file - #50
Merged
Conversation
Login resolved ~/.asobi/credentials.json by joining an ignored os.UserHomeDir() error, so with no resolvable HOME it silently wrote to a relative .asobi/ under the working directory while still reporting success - stale tokens stayed in place and every later command failed with invalid_refresh_token. Resolve the path up front and fail before the device-code dance if it cannot be determined, write the file atomically, print the real path, and remove the pre-credentials.json ~/.asobi/auth token file on login and logout.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #46
credentialsPath()joined the result ofos.UserHomeDir()with its error ignored. When the home directory cannot be resolved that yields the relative path.asobi/credentials.json, soasobi loginwrote its tokens into whatever directory it was invoked from, printed "Login successful" and the hardcoded~/.asobi/credentials.json, and left the previous credentials untouched - subsequent commands kept using the stale tokens and failed withinvalid_refresh_token.CredentialsPath()is now exported and returns an error instead of falling back to a relative path; load/save/delete propagate it.cmdLoginresolves the path before starting the device-code flow, so an unusable environment fails immediately rather than after the user has approved the session.SaveCredentialswrites to a temp file in the target directory and renames it into place, so a failed write cannot leave a partial file or silently preserve the old tokens.credentials.json~/.asobi/authtoken file is removed on login and on logout, so an old binary still on PATH cannot resurrect expired tokens.Tests cover re-login replacing stale tokens, the missing-home-dir failure (and that nothing is written to a relative
.asobi/), and legacy-file removal being idempotent and leavingcredentials.jsonintact.