Function: url-get-authentication

url-get-authentication is an autoloaded and byte-compiled function defined in url-auth.el.gz.

Signature

(url-get-authentication URL REALM TYPE PROMPT &optional ARGS)

Documentation

Return authorization string for the WWW-Authenticate header in HTTP/1.0 request.

URL is the url you are requesting authorization to. This can be either a
       string representing the URL, or the parsed representation returned by
       url-generic-parse-url
REALM is the realm at a specific site we are looking for. This should be a
       string specifying the exact realm, or nil or the symbol any to
       specify that the filename portion of the URL should be used as the
       realm
TYPE is the type of authentication to be returned. This is either a string
       representing the type (basic, digest, etc), or nil or the symbol any
       to specify that any authentication is acceptable. If requesting any
       the strongest matching authentication will be returned. If this is
       wrong, it's no big deal, the error from the server will specify exactly
       what type of auth to use
PROMPT is boolean - specifies whether to ask the user for a username/password
       if one cannot be found in the cache

Source Code

;; Defined in /usr/src/emacs/lisp/url/url-auth.el.gz
;;;###autoload
(defun url-get-authentication (url realm type prompt &optional args)
  "Return authorization string for the WWW-Authenticate header in HTTP/1.0 request.

URL    is the url you are requesting authorization to.  This can be either a
       string representing the URL, or the parsed representation returned by
       `url-generic-parse-url'
REALM  is the realm at a specific site we are looking for.  This should be a
       string specifying the exact realm, or nil or the symbol `any' to
       specify that the filename portion of the URL should be used as the
       realm
TYPE   is the type of authentication to be returned.  This is either a string
       representing the type (basic, digest, etc), or nil or the symbol `any'
       to specify that any authentication is acceptable.  If requesting `any'
       the strongest matching authentication will be returned.  If this is
       wrong, it's no big deal, the error from the server will specify exactly
       what type of auth to use
PROMPT is boolean - specifies whether to ask the user for a username/password
       if one cannot be found in the cache"
  (if (not realm)
      (setq realm (cdr-safe (assoc "realm" args))))
  (if (equal realm "")
      (setq realm nil))
  (if (stringp url)
      (setq url (url-generic-parse-url url)))
  (if (or (null type) (eq type 'any))
      ;; Whooo doogies!
      ;; Go through and get _all_ the authorization strings that could apply
      ;; to this URL, store them along with the 'rating' we have in the list
      ;; of schemes, then sort them so that the 'best' is at the front of the
      ;; list, then get the car, then get the cdr.
      ;; Zooom zooom zoooooom
      (cdr-safe
       (car-safe
	(sort
	 (mapcar
          (lambda (scheme)
            (if (fboundp (car (cdr scheme)))
                (cons (cdr (cdr scheme))
                      (funcall (car (cdr scheme)) url nil nil realm))
              (cons 0 nil)))
	  url-registered-auth-schemes)
         (lambda (x y)
           (cond
            ((null (cdr x)) nil)
            ((and (cdr x) (null (cdr y))) t)
            ((and (cdr x) (cdr y))
             (>= (car x) (car y)))
            (t nil))))))
    (if (symbolp type) (setq type (symbol-name type)))
    (let* ((scheme (car-safe
		    (cdr-safe (assoc (downcase type)
				     url-registered-auth-schemes)))))
      (if (and scheme (fboundp scheme))
	  (funcall scheme url prompt
		   (and prompt
			(funcall scheme url nil nil realm args))
		   realm args)))))