fix(security): use keyring to store tokens upon login#123
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances security by migrating token storage from local config (using Viper) to the OS keyring.
- Introduces a new
tokenspackage leveraginggo-keyringto set, get, and clear tokens. - Updates API utilities, commands, and
main.goto use keyring-based token operations instead of Viper. - Removes sensitive debug logging of client credentials in the
Me()method.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| unsplash/util.go | Switched from viper.GetString to tokens.GetAccessToken and simplified debug logs. |
| unsplash/tokens/tokens.go | New package to store, retrieve, and clear access/refresh tokens via keyring. |
| unsplash/auth.go | Removed debug logging of client_id and client_secret. |
| main.go | Replaced Viper-based token retrieval with keyring-based tokens.Get*. |
| cmd/auth/whoami.go | Updated to retrieve the access token from keyring. |
| cmd/auth/logout.go | Added tokens.Clear() before clearing Viper entries. |
| cmd/auth/login.go | Switched to tokens.Set* for storing tokens and fixed authenticationURL naming. |
| go.mod | Added go-keyring and updated indirect dependencies for keyring support. |
| Run: func(cmd *cobra.Command, args []string) { | ||
| fmt.Println("Logging out...") | ||
|
|
||
| tokens.Clear() |
There was a problem hiding this comment.
After clearing tokens in the keyring, the Viper config is set but not persisted; add viper.WriteConfig() to ensure the config file no longer retains auth tokens.
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.
No description provided.