aboutsummaryrefslogtreecommitdiffstats
path: root/doc/misc/auth.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/misc/auth.texi')
-rw-r--r--doc/misc/auth.texi74
1 files changed, 69 insertions, 5 deletions
diff --git a/doc/misc/auth.texi b/doc/misc/auth.texi
index 23ac23dce5b..a16da92343e 100644
--- a/doc/misc/auth.texi
+++ b/doc/misc/auth.texi
@@ -131,11 +131,11 @@ library encourages this confusion by accepting both, as you'll see
131later. 131later.
132 132
133If you have problems with the search, set @code{auth-source-debug} to 133If you have problems with the search, set @code{auth-source-debug} to
134@code{t} and see what host, port, and user the library is checking in 134@code{'trivia} and see what host, port, and user the library is
135the @code{*Messages*} buffer. Ditto for any other problems, your 135checking in the @code{*Messages*} buffer. Ditto for any other
136first step is always to see what's being checked. The second step, of 136problems, your first step is always to see what's being checked. The
137course, is to write a blog entry about it and wait for the answer in 137second step, of course, is to write a blog entry about it and wait for
138the comments. 138the answer in the comments.
139 139
140You can customize the variable @code{auth-sources}. The following may 140You can customize the variable @code{auth-sources}. The following may
141be needed if you are using an older version of Emacs or if the 141be needed if you are using an older version of Emacs or if the
@@ -232,6 +232,14 @@ TODO: how does it work generally, how does secrets.el work, some examples.
232@node Help for developers 232@node Help for developers
233@chapter Help for developers 233@chapter Help for developers
234 234
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
235The auth-source library only has a few functions for external use. 243The auth-source library only has a few functions for external use.
236 244
237@defun auth-source-search SPEC 245@defun auth-source-search SPEC
@@ -240,6 +248,62 @@ TODO: how to include docstring?
240 248
241@end defun 249@end defun
242 250
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)
266 (let ((secret (plist-get found :secret)))
267 (if (functionp secret)
268 (funcall secret)
269 secret))
270 (plist-get found :save-function))
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
284Later, after a successful login, @code{nnimal.el} calls the
285@code{:save-function} like so:
286
287@example
288(when (functionp (nth 2 credentials))
289 (funcall (nth 2 credentials)))
290@end example
291
292This will work whether the @code{:save-function} was provided or not.
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
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
243@defun auth-source-delete SPEC 307@defun auth-source-delete SPEC
244 308
245TODO: how to include docstring? 309TODO: how to include docstring?