     [file gnus-overrides.texi not included]

Emacs auth-source
*****************

This manual describes the Emacs auth-source library.

It is a way for multiple applications to share a single configuration (in Emacs and in files) for user convenience.

This file describes the Emacs auth-source library.

Copyright © 2008-2011 Free Software Foundation, Inc.

     Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover texts being ``A GNU Manual,'' and with the Back-Cover Texts as in (a) below.  A copy of the license is included in the section entitled ``GNU Free Documentation License'' in the Emacs manual.

     (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and modify this GNU manual.  Buying copies from the FSF supports it in developing GNU and promoting software freedom.''

     This document is part of a collection distributed under the GNU Free Documentation License.  If you want to distribute this document separately from the collection, you can do so by adding a copy of the license to the document, as described in section 6 of the license.

Overview
********

The auth-source library is simply a way for Emacs and Gnus, among others, to answer the old burning question ``What are my user name and password?''

(This is different from the old question about burning ``Where is the fire extinguisher, please?''.)

The auth-source library supports more than just the user name or the password (known as the secret).

Similarly, the auth-source library supports multiple storage backend, currently either the classic ``netrc'' backend, examples of which you can see later in this document, or the Secret Service API.  This is done with EIEIO-based backends and you can write your own if you want.

Help for users
**************

``Netrc'' files are a de facto standard.  They look like this:

     machine MYMACHINE login MYLOGINNAME password MYPASSWORD port MYPORT

The machine is the server (either a DNS name or an IP address). It's known as :HOST in auth-source-search queries.  You can also use host.

The port is the connection port or protocol.  It's known as :PORT in auth-source-search queries.  You can also use protocol.

The user is the user name.  It's known as :USER in auth-source-search queries.  You can also use login and account.

Spaces are always OK as far as auth-source is concerned (but other programs may not like them).  Just put the data in quotes, escaping quotes as you'd expect with \.

All these are optional.  You could just say (but we don't recommend it, we're just showing that it's possible)

     password MYPASSWORD

to use the same password everywhere.  Again, DO NOT DO THIS or you will be pwned as the kids say.

``Netrc'' files are usually called .authinfo or .netrc; nowadays .authinfo seems to be more popular and the auth-source library encourages this confusion by making it the default, as you'll see later.

If you have problems with the search, set auth-source-debug to t and see what host, port, and user the library is checking in the *Messages* buffer.  Ditto for any other problems, your first step is always to see what's being checked.  The second step, of course, is to write a blog entry about it and wait for the answer in the comments.

You can customize the variable auth-sources.  The following may be needed if you are using an older version of Emacs or if the auth-source library is not loaded for some other reason.

     (require 'auth-source)             ;; probably not necessary
     (customize-variable 'auth-sources) ;; optional, do it once

 -- Variable: auth-sources

     The auth-sources variable tells the auth-source library where your netrc files or Secret Service API collection items live for a particular host and protocol.  While you can get fancy, the default and simplest configuration is:

          ;;; old default: required :host and :protocol, not needed anymore
          (setq auth-sources '((:source "~/.authinfo.gpg" :host t :protocol t)))
          ;;; mostly equivalent (see below about fallbacks) but shorter:
          (setq auth-sources '((:source "~/.authinfo.gpg")))
          ;;; even shorter and the default:
          (setq auth-sources '("~/.authinfo.gpg" "~/.authinfo"))
          ;;; use the Secrets API LOGIN collection (see Secret Service API)
          (setq auth-sources '("secrets:login"))

     By adding multiple entries to auth-sources with a particular host or protocol, you can have specific netrc files for that host or protocol.  Usually this is unnecessary but may make sense if you have shared netrc files or some other unusual setup (90% of Emacs users have unusual setups and the remaining 10% are really unusual).

     Here's a mixed example using two sources:

          (setq auth-sources '((:source (:secrets default) :host "myserver" :user "joe")
                               "~/.authinfo.gpg"))

If you don't customize auth-sources, you'll have to live with the defaults: any host and any port are looked up in the netrc file ~/.authinfo.gpg, which is a GnuPG encrypted file (see GnuPG and EasyPG Assistant Configuration).

If that fails, the unencrypted netrc file ~/.authinfo will be used.

The typical netrc line example is without a port.

     machine YOURMACHINE login YOU password YOURPASSWORD

This will match any authentication port.  Simple, right?  But what if there's a SMTP server on port 433 of that machine that needs a different password from the IMAP server?

     machine YOURMACHINE login YOU password SMTPPASSWORD port 433
     machine YOURMACHINE login YOU password GENERALPASSWORD

For url-auth authentication (HTTP/HTTPS), you need to put this in your netrc file:

     machine yourmachine.com:80 port http login testuser password testpass

This will match any realm and authentication method (basic or digest) over HTTP.  HTTPS is set up similarly.  If you want finer controls, explore the url-auth source code and variables.

For Tramp authentication, use:

     machine yourmachine.com port scp login testuser password testpass

Note that the port denotes the Tramp connection method.  When you don't use a port entry, you match any Tramp method, as explained earlier.  Since Tramp has about 88 connection methods, this may be necessary if you have an unusual (see earlier comment on those) setup.

Secret Service API
******************

TODO: how does it work generally, how does secrets.el work, some examples.

Help for developers
*******************

The auth-source library only has a few functions for external use.

 -- Function: auth-source-search SPEC

     TODO: how to include docstring?

 -- Function: auth-source-delete SPEC

     TODO: how to include docstring?

 -- Function: auth-source-forget SPEC

     TODO: how to include docstring?

 -- Function: auth-source-forget+ SPEC

     TODO: how to include docstring?

GnuPG and EasyPG Assistant Configuration
****************************************

If you don't customize auth-sources, the auth-source library reads ~/.authinfo.gpg, which is a GnuPG encrypted file.

In Emacs 23 or later there is an option auto-encryption-mode to automatically decrypt *.gpg files.  It is enabled by default. If you are using earlier versions of Emacs, you will need:

     (require 'epa-file)
     (epa-file-enable)

If you want your GnuPG passwords to be cached, set up gpg-agent or EasyPG Assitant (see Caching Passphrases (epa)).

To quick start, here are some questions:

 1. Do you use GnuPG version 2 instead of GnuPG version 1?

 2. Do you use symmetric encryption rather than public key encryption?

 3. Do you want to use gpg-agent?

Here are configurations depending on your answers:

1   2   3   Configuration
Yes   Yes   Yes   Set up gpg-agent.
Yes   Yes   No   You can't, without gpg-agent.
Yes   No   Yes   Set up gpg-agent.
Yes   No   No   You can't, without gpg-agent.
No   Yes   Yes   Set up elisp passphrase cache.
No   Yes   No   Set up elisp passphrase cache.
No   No   Yes   Set up gpg-agent.
No   No   No   You can't, without gpg-agent.

To set up gpg-agent, follow the instruction in GnuPG manual (see Invoking GPG-AGENT (gnupg)).

To set up elisp passphrase cache, set epa-file-cache-passphrase-for-symmetric-encryption.