Add 2012 to FSF copyright years for Emacs files
[bpt/emacs.git] / doc / misc / auth.texi
CommitLineData
9eb59592 1\input texinfo @c -*-texinfo-*-
7fbf7cae
TZ
2
3@include gnus-overrides.texi
4
e280480a 5@setfilename ../../info/auth
5dc584b5 6@settitle Emacs auth-source Library @value{VERSION}
9eb59592 7
b8e0f0cd 8@set VERSION 0.3
9eb59592 9
9eb59592
MB
10@copying
11This file describes the Emacs auth-source library.
12
acaf905b 13Copyright @copyright{} 2008-2012 Free Software Foundation, Inc.
9eb59592
MB
14
15@quotation
16Permission is granted to copy, distribute and/or modify this document
17under the terms of the GNU Free Documentation License, Version 1.3 or
18any later version published by the Free Software Foundation; with no
19Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
20and with the Back-Cover Texts as in (a) below. A copy of the license
21is included in the section entitled ``GNU Free Documentation License''
22in the Emacs manual.
23
24(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
25modify this GNU manual. Buying copies from the FSF supports it in
26developing GNU and promoting software freedom.''
27
28This document is part of a collection distributed under the GNU Free
29Documentation License. If you want to distribute this document
30separately from the collection, you can do so by adding a copy of the
31license to the document, as described in section 6 of the license.
32@end quotation
33@end copying
34
0c973505 35@dircategory Emacs lisp libraries
5dc584b5 36@direntry
62e034c2 37* Auth-source: (auth). The Emacs auth-source library.
5dc584b5 38@end direntry
9eb59592
MB
39
40@titlepage
7fbf7cae
TZ
41@ifset WEBHACKDEVEL
42@title Emacs auth-source Library (DEVELOPMENT VERSION)
43@end ifset
44@ifclear WEBHACKDEVEL
9eb59592 45@title Emacs auth-source Library
7fbf7cae 46@end ifclear
9eb59592
MB
47@author by Ted Zlatanov
48@page
9eb59592
MB
49@vskip 0pt plus 1filll
50@insertcopying
51@end titlepage
9eb59592 52
5dc584b5 53@contents
9eb59592 54
5dc584b5 55@ifnottex
9eb59592
MB
56@node Top
57@top Emacs auth-source
58This manual describes the Emacs auth-source library.
59
60It is a way for multiple applications to share a single configuration
61(in Emacs and in files) for user convenience.
62
5dc584b5
KB
63@insertcopying
64
9eb59592
MB
65@menu
66* Overview:: Overview of the auth-source library.
fe3c5669
PE
67* Help for users::
68* Secret Service API::
69* Help for developers::
70* GnuPG and EasyPG Assistant Configuration::
71* Index::
72* Function Index::
73* Variable Index::
9eb59592 74@end menu
5dc584b5 75@end ifnottex
9eb59592
MB
76
77@node Overview
78@chapter Overview
79
38dc51ba 80The auth-source library is simply a way for Emacs and Gnus, among
b8e0f0cd
G
81others, to answer the old burning question ``What are my user name and
82password?''
b0b63450 83
b8e0f0cd
G
84(This is different from the old question about burning ``Where is the
85fire extinguisher, please?''.)
86
87The auth-source library supports more than just the user name or the
88password (known as the secret).
89
90Similarly, the auth-source library supports multiple storage backend,
91currently either the classic ``netrc'' backend, examples of which you
92can see later in this document, or the Secret Service API. This is
93done with EIEIO-based backends and you can write your own if you want.
9eb59592
MB
94
95@node Help for users
96@chapter Help for users
97
b0b63450
MB
98``Netrc'' files are a de facto standard. They look like this:
99@example
38dc51ba 100machine @var{mymachine} login @var{myloginname} password @var{mypassword} port @var{myport}
b0b63450 101@end example
9eb59592 102
b8e0f0cd
G
103The @code{machine} is the server (either a DNS name or an IP address).
104It's known as @var{:host} in @code{auth-source-search} queries. You
105can also use @code{host}.
106
107The @code{port} is the connection port or protocol. It's known as
35123c04 108@var{:port} in @code{auth-source-search} queries.
b8e0f0cd
G
109
110The @code{user} is the user name. It's known as @var{:user} in
111@code{auth-source-search} queries. You can also use @code{login} and
112@code{account}.
113
114Spaces are always OK as far as auth-source is concerned (but other
115programs may not like them). Just put the data in quotes, escaping
116quotes as you'd expect with @code{\}.
117
118All these are optional. You could just say (but we don't recommend
119it, we're just showing that it's possible)
38dc51ba 120
b8e0f0cd
G
121@example
122password @var{mypassword}
123@end example
38dc51ba 124
b8e0f0cd
G
125to use the same password everywhere. Again, @emph{DO NOT DO THIS} or
126you will be pwned as the kids say.
38dc51ba
KY
127
128``Netrc'' files are usually called @code{.authinfo} or @code{.netrc};
129nowadays @code{.authinfo} seems to be more popular and the auth-source
4a3988d5
G
130library encourages this confusion by accepting both, as you'll see
131later.
38dc51ba 132
b8e0f0cd 133If you have problems with the search, set @code{auth-source-debug} to
733afdf4
TZ
134@code{'trivia} and see what host, port, and user the library is
135checking in the @code{*Messages*} buffer. Ditto for any other
136problems, your first step is always to see what's being checked. The
137second step, of course, is to write a blog entry about it and wait for
138the answer in the comments.
38dc51ba
KY
139
140You can customize the variable @code{auth-sources}. The following may
b0b63450
MB
141be needed if you are using an older version of Emacs or if the
142auth-source library is not loaded for some other reason.
9eb59592
MB
143
144@lisp
b0b63450 145(require 'auth-source) ;; probably not necessary
9eb59592
MB
146(customize-variable 'auth-sources) ;; optional, do it once
147@end lisp
148
149@defvar auth-sources
150
38dc51ba 151The @code{auth-sources} variable tells the auth-source library where
bd3e840f
KY
152your netrc files or Secret Service API collection items live for a
153particular host and protocol. While you can get fancy, the default
154and simplest configuration is:
9eb59592
MB
155
156@lisp
35123c04
TZ
157;;; old default: required :host and :port, not needed anymore
158(setq auth-sources '((:source "~/.authinfo.gpg" :host t :port t)))
bd3e840f
KY
159;;; mostly equivalent (see below about fallbacks) but shorter:
160(setq auth-sources '((:source "~/.authinfo.gpg")))
b8e0f0cd 161;;; even shorter and the @emph{default}:
4a3988d5 162(setq auth-sources '("~/.authinfo.gpg" "~/.authinfo" "~/.netrc"))
5415d076
G
163;;; use the Secrets API @var{Login} collection (@pxref{Secret Service API})
164(setq auth-sources '("secrets:Login"))
9eb59592
MB
165@end lisp
166
38dc51ba 167By adding multiple entries to @code{auth-sources} with a particular
b0b63450
MB
168host or protocol, you can have specific netrc files for that host or
169protocol. Usually this is unnecessary but may make sense if you have
170shared netrc files or some other unusual setup (90% of Emacs users
171have unusual setups and the remaining 10% are @emph{really} unusual).
9eb59592 172
b8e0f0cd 173Here's a mixed example using two sources:
bd3e840f
KY
174
175@lisp
176(setq auth-sources '((:source (:secrets default) :host "myserver" :user "joe")
b8e0f0cd 177 "~/.authinfo.gpg"))
bd3e840f
KY
178@end lisp
179
b0b63450 180@end defvar
9eb59592 181
38dc51ba 182If you don't customize @code{auth-sources}, you'll have to live with
9eb59592 183the defaults: any host and any port are looked up in the netrc
a1d16a7b 184file @code{~/.authinfo.gpg}, which is a GnuPG encrypted file
fe3c5669 185(@pxref{GnuPG and EasyPG Assistant Configuration}).
b8e0f0cd 186
4a3988d5
G
187If that fails, the unencrypted netrc files @code{~/.authinfo} and
188@code{~/.netrc} will be used.
9eb59592 189
b8e0f0cd 190The typical netrc line example is without a port.
b0b63450
MB
191
192@example
193machine YOURMACHINE login YOU password YOURPASSWORD
194@end example
195
196This will match any authentication port. Simple, right? But what if
197there's a SMTP server on port 433 of that machine that needs a
198different password from the IMAP server?
199
200@example
201machine YOURMACHINE login YOU password SMTPPASSWORD port 433
202machine YOURMACHINE login YOU password GENERALPASSWORD
203@end example
204
9eb59592
MB
205For url-auth authentication (HTTP/HTTPS), you need to put this in your
206netrc file:
207
208@example
209machine yourmachine.com:80 port http login testuser password testpass
210@end example
211
b0b63450
MB
212This will match any realm and authentication method (basic or digest)
213over HTTP. HTTPS is set up similarly. If you want finer controls,
214explore the url-auth source code and variables.
9eb59592
MB
215
216For Tramp authentication, use:
217
218@example
219machine yourmachine.com port scp login testuser password testpass
220@end example
221
222Note that the port denotes the Tramp connection method. When you
223don't use a port entry, you match any Tramp method, as explained
b0b63450
MB
224earlier. Since Tramp has about 88 connection methods, this may be
225necessary if you have an unusual (see earlier comment on those) setup.
9eb59592 226
bd3e840f
KY
227@node Secret Service API
228@chapter Secret Service API
229
230TODO: how does it work generally, how does secrets.el work, some examples.
231
9eb59592
MB
232@node Help for developers
233@chapter Help for developers
234
733afdf4
TZ
235The auth-source library lets you control logging output easily.
236
237@defvar auth-source-debug
238Set this variable to 'trivia to see lots of output in *Messages*, or
239set it to a function that behaves like @code{message} to do your own
240logging.
241@end defvar
242
b8e0f0cd 243The auth-source library only has a few functions for external use.
9eb59592 244
b8e0f0cd 245@defun auth-source-search SPEC
9eb59592 246
b8e0f0cd 247TODO: how to include docstring?
9eb59592 248
b8e0f0cd 249@end defun
9eb59592 250
733afdf4
TZ
251Let's take a look at an example of using @code{auth-source-search}
252from Gnus' @code{nnimap.el}.
253
254@example
255(defun nnimap-credentials (address ports)
256 (let* ((auth-source-creation-prompts
257 '((user . "IMAP user at %h: ")
258 (secret . "IMAP password for %u@@%h: ")))
259 (found (nth 0 (auth-source-search :max 1
260 :host address
261 :port ports
262 :require '(:user :secret)
263 :create t))))
264 (if found
265 (list (plist-get found :user)
3107d2a5
KY
266 (let ((secret (plist-get found :secret)))
267 (if (functionp secret)
268 (funcall secret)
269 secret))
270 (plist-get found :save-function))
733afdf4
TZ
271 nil)))
272@end example
273
274This call requires the user and password (secret) to be in the
275results. It also requests that an entry be created if it doesn't
276exist already. While the created entry is being assembled, the shown
277prompts will be used to interact with the user. The caller can also
278pass data in @code{auth-source-creation-defaults} to supply defaults
279for any of the prompts.
280
281Note that the password needs to be evaluated if it's a function. It's
282wrapped in a function to provide some security.
283
6196cffe 284Later, after a successful login, @code{nnimap.el} calls the
733afdf4
TZ
285@code{:save-function} like so:
286
287@example
288(when (functionp (nth 2 credentials))
289 (funcall (nth 2 credentials)))
3107d2a5 290@end example
733afdf4 291
4248cca2 292This will work whether the @code{:save-function} was provided or not.
733afdf4
TZ
293@code{:save-function} will be provided only when a new entry was
294created, so this effectively says ``after a successful login, save the
295authentication information we just used, if it was newly created.''
296
4248cca2
TZ
297After the first time it's called, the @code{:save-function} will not
298run again (but it will log something if you have set
299@code{auth-source-debug} to @code{'trivia}). This is so it won't ask
300the same question again, which is annoying. This is so it won't ask
301the same question again, which is annoying. This is so it won't ask
302the same question again, which is annoying.
303
304So the responsibility of the API user that specified @code{:create t}
305is to call the @code{:save-function} if it's provided.
306
b8e0f0cd 307@defun auth-source-delete SPEC
9eb59592 308
b8e0f0cd 309TODO: how to include docstring?
9eb59592 310
b8e0f0cd 311@end defun
bd3e840f 312
b8e0f0cd
G
313@defun auth-source-forget SPEC
314
315TODO: how to include docstring?
316
317@end defun
318
319@defun auth-source-forget+ SPEC
320
321TODO: how to include docstring?
9eb59592
MB
322
323@end defun
324
36d3245f
G
325@node GnuPG and EasyPG Assistant Configuration
326@appendix GnuPG and EasyPG Assistant Configuration
327
98e2b864 328If you don't customize @code{auth-sources}, the auth-source library
7ba93e94
G
329reads @code{~/.authinfo.gpg}, which is a GnuPG encrypted file. Then
330it will check @code{~/.authinfo} but it's not recommended to use such
331an unencrypted file.
98e2b864 332
36d3245f 333In Emacs 23 or later there is an option @code{auto-encryption-mode} to
a1d16a7b
G
334automatically decrypt @code{*.gpg} files. It is enabled by default.
335If you are using earlier versions of Emacs, you will need:
36d3245f
G
336
337@lisp
338(require 'epa-file)
339(epa-file-enable)
340@end lisp
341
98e2b864 342If you want your GnuPG passwords to be cached, set up @code{gpg-agent}
fe3c5669 343or EasyPG Assistant
c56dfd36 344(@pxref{Caching Passphrases, , Caching Passphrases, epa}).
36d3245f 345
98e2b864 346To quick start, here are some questions:
36d3245f
G
347
348@enumerate
a1d16a7b
G
349@item
350Do you use GnuPG version 2 instead of GnuPG version 1?
351@item
352Do you use symmetric encryption rather than public key encryption?
353@item
354Do you want to use gpg-agent?
36d3245f
G
355@end enumerate
356
357Here are configurations depending on your answers:
358
359@multitable {111} {222} {333} {configuration configuration configuration}
360@item @b{1} @tab @b{2} @tab @b{3} @tab Configuration
98e2b864 361@item Yes @tab Yes @tab Yes @tab Set up gpg-agent.
36d3245f 362@item Yes @tab Yes @tab No @tab You can't, without gpg-agent.
98e2b864 363@item Yes @tab No @tab Yes @tab Set up gpg-agent.
36d3245f
G
364@item Yes @tab No @tab No @tab You can't, without gpg-agent.
365@item No @tab Yes @tab Yes @tab Set up elisp passphrase cache.
366@item No @tab Yes @tab No @tab Set up elisp passphrase cache.
98e2b864 367@item No @tab No @tab Yes @tab Set up gpg-agent.
36d3245f
G
368@item No @tab No @tab No @tab You can't, without gpg-agent.
369@end multitable
370
a1d16a7b
G
371To set up gpg-agent, follow the instruction in GnuPG manual
372(@pxref{Invoking GPG-AGENT, , Invoking GPG-AGENT, gnupg}).
36d3245f
G
373
374To set up elisp passphrase cache, set
375@code{epa-file-cache-passphrase-for-symmetric-encryption}.
376
9eb59592
MB
377@node Index
378@chapter Index
379@printindex cp
380
381@node Function Index
382@chapter Function Index
383@printindex fn
384
385@node Variable Index
386@chapter Variable Index
387@printindex vr
388
9eb59592
MB
389@bye
390
391@c End: