emacs-slack icon indicating copy to clipboard operation
emacs-slack copied to clipboard

Read credentials from authinfo file

Open kostajh opened this issue 9 years ago • 6 comments

It would be nice to store the client-secret, token and client-id in the user's authinfo file.

kostajh avatar Jan 25 '16 15:01 kostajh

The best solution would be to use auth-sources. In emacs 25, auth-sources was enhanced to support external sources. For example, the auth-source-pass package uses pass as a backend:

(defun auth-source-pass-enable ()
  "Enable auth-source-password-store."
  ;; To add password-store to the list of sources, evaluate the following:
  (add-to-list 'auth-sources 'password-store)
  ;; clear the cache (required after each change to #'auth-source-pass-search)
  (auth-source-forget-all-cached))

The way auth-sources is populated above, authinfo will still be used as a fallback.

creichert avatar Oct 09 '18 19:10 creichert

I get

Failed to request slack-authorize: invalid_auth [2 times]

My config looks like this:

(setq auth-source-debug t) (load "~/Yandex.Disk/private/slack.el") (defun auth-source-pass-enable () "Enable auth-source-password-store." ;; To add password-store to the list of sources, evaluate the following: (add-to-list 'auth-sources 'password-store) ;; clear the cache (required after each change to #'auth-source-pass-search) (auth-source-forget-all-cached)) (setenv "GPG_AGENT_INFO" nil) (auth-source-pass-enable)

I have the packages [auth-source-pass, password-store, password-store-otp] installed

I am not sure how to get emacs-slack to work with my password store that I generated with pass insert -m [email protected] where [email protected] is my email address and the file looks like this

mypassword URL: .slack.com/ Username: [email protected] client-id: numbers... token: blah...

I created a file slack.el which I load into my config

(slack-register-team :name "nix duo" :default t :token "token" :subscribed-channels '(general slackbot))

Do you think that you could help with this.

slipsnip avatar May 29 '19 04:05 slipsnip

You're going to need to call auth-source-search to get the password and token data from pass, and then use plist-get to read the individual fields. Something like this:

(let ((auth (car (auth-source-search :host "slack.com"))))
  (slack-register-team
    :name "nix duo"
    :default t
    :client-id (plist-get auth :client-id)
    :token (plist-get auth :token)
    :subscribed-channels '(general slackbot)))

gonewest818 avatar Feb 09 '20 04:02 gonewest818

The documentation is updated but it could still be problematic for a beginner. The below solution worked for me:

(slack-register-team
 ;; other stuff
 :client-secret (auth-source-pick-first-password
                       :host '("yourchannel.slack.com")
                       :user "secret" :type 'netrc :max 1)
 :token (auth-source-pick-first-password
               :host '("yourchannel.slack.com")
               :user "token" :type 'netrc :max 1)
 ; other stuff
)

and put the corresponding entries in your ~/.authinfo.gpg, e..g machine yourchannel.slack.com login token password xoxs-yyyyyyyyyy... <-here you put the actual token you retrieved from Chrome Dev tools.

ealvar3z avatar Sep 13 '20 07:09 ealvar3z

Hi. It's been a while since I've looked at this, but I don't believe your :client-secret is needed or even used by slack-register-team. You just need to supply the :token, or at least that's all I am doing.

In other words, I think you just need this in your authinfo file

machine yourchannel.slack.com login token password xoxs-yyyyyyyyyy... 

and this in your config

(slack-register-team
 ;; other stuff
 :token (auth-source-pick-first-password
               :host '("yourchannel.slack.com")
               :user "token" :type 'netrc :max 1)
 ; other stuff
)

gonewest818 avatar Sep 18 '20 04:09 gonewest818

Oh, I see what you're saying. I added the client secret in case you do not want to manually type the password for your encrypted .gpg file every time it gets called.

ealvar3z avatar Sep 27 '20 01:09 ealvar3z