gpt-commit icon indicating copy to clipboard operation
gpt-commit copied to clipboard

Read api key from .authinfo for better security

Open akagr opened this issue 1 year ago • 0 comments

It'd be great if there's a way to pull api keys from .authinfo. An added benefit is that if that file is encrypted with gpg, emacs will handle that transparently.

An example of how to do this is as follows:

Assuming following is present in .authinfo or .authinfo.gpg:

machine api.openai.com login apikey password 1234567890

This bit of emacs lisp returns the password (api key):

(encode-coding-string (funcall 
  (plist-get (car
    (auth-source-search :host "api.openai.com" :user "apikey" :require '(:secret)))
   :secret)) 'utf-8)

;; =>  "1234567890"

I'll look at making a PR with this once I get some more time.

akagr avatar Jan 07 '25 15:01 akagr