-
Notifications
You must be signed in to change notification settings - Fork 332
gptel-gh: Change how tokens are managed #1058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
gptel-gh: Change how tokens are managed #1058
Conversation
68b1fc9 to
76a1010
Compare
|
@karthink - Do you have any input in how you imagine the workflow to be for this API regarding the GitHub token? With the changes made just recently to present the login function, is it reasonable to have a workflow to perform that in order to get the token that can then be stored elsewhere? |
|
@karthink - Do you have any input in how you imagine the workflow to be for this API regarding the GitHub token?
With the changes made just recently to present the login function, is it reasonable to have a workflow to perform that in order to get the token that can then be stored elsewhere?
Sorry, I haven't looked at this PR yet. I also don't use Copilot so let's hear from @kiennq (the author of gptel-gh) on the proposed changes.
|
b31c107 to
7fa9017
Compare
|
@kiennq - A friendly reminder about this PR :) |
|
Sorry for the late reply. Can you add a default/example for |
|
Thanks for your reply, @kiennq! This is what I am currently using: (use-package gptel
:defer t
:config (setq
gptel-backend (gptel-make-gh-copilot "Copilot"
:github-token-init (lambda () (read-passwd "Copilot token: "))))
)I store my token in a password manager, so I use With the current implementation in this PR, the login function is not able to persistently store the newly acquired token. The new token is only stored in a variable and I take the it from the message log, which is not an ideal scenario and hence my request for feedback earlier. Another approach could be to introduce load and save functions that can be given as parameters to Before making the changes in gptel itself, I used the code below as a patch to control how the token was stored. This also has the behavior of only requesting the token once. As you may notice, the logic for the chat message token was kept, but this was before me realising that that is also a thing to keep secret. (use-package gptel
:config
(progn
(defvar my/gh-token nil "Store the Copilot token for GPTel commands.")
(defalias 'original-gptel--gh-save (symbol-function 'gptel--gh-save))
(defalias 'original-gptel--gh-restore (symbol-function 'gptel--gh-restore))
(defun gptel--gh-restore (file)
(if (equal file gptel-gh-github-token-file)
(if my/gh-token
my/gh-token
(progn
(setq my/gh-token
(let ((token (read-passwd "Copilot token: ")))
(if (string= "" token) nil token)))
my/gh-token))
(original-gptel--gh-restore file)))
(defun gptel--gh-save (file obj)
(message "New GH token: %s" obj)
(if (equal file gptel-gh-github-token-file)
(setq my/gh-token obj)
(original-gptel--gh-save file obj))))) |
7fa9017 to
c293cbf
Compare
|
@kiennq - Any thoughts? :) |
c293cbf to
63c1bec
Compare
63c1bec to
83b7a84
Compare
|
@kiennq - I've now changed the implementation so that it defaults to use the file as before for the github-token. What has been additionally added is the ability to create a custom save function for the github-token. This solves the question that I raised before, as it is now up to the one redefining the save function to decide how to handle an update. A sample use-package snippet to override it: (use-package gptel
:defer t
:config
(defvar my/gh-token nil "Store the Copilot token for GPTel commands.")
(setq
gptel-gh-github-token-load (lambda ()
(if my/gh-token
my/gh-token
(progn
(setq my/gh-token
(let ((token (read-passwd "Copilot token: ")))
(if (string= "" token) nil token)))
my/gh-token)))
gptel-gh-github-token-save (lambda (token)
(setq my/gh-token token))
gptel-backend (gptel-make-gh-copilot "Copilot"))
) |
c0727e8 to
0bc293c
Compare
0ed7be3 to
51ba56e
Compare
|
@marcus-lundgren just dropping a note to say this PR remains on my radar -- I just need a longer chunk of time to review it than other PRs since I'm not the author of the token management code. I'll do a general code review but I trust @kiennq's judgment on the design. |
|
@karthink - thank you for the status update! As you may have noticed, I am rebasing the branch continuously to fix any conflicts (as happened a few days ago). |
(float-time) will implicitly use (current-time) if the argument is not specified.
Removed the file based persistent storage of the chat token. Introduced overloadable function variables that determines how a token is loaded and saved.
51ba56e to
c67ae91
Compare
Removed the file based persistent storage of the tokens, as they were stored in clear text. They will only be stored in variables.
The initial value of the github-token can now be set by providing a function that provides it. This enables this token to be securely stored outside of Emacs.