Skip to content

Read api key from .authinfo for better security #5

@akagr

Description

@akagr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions