emacs的url如何处理身份验证? [英] How does emacs url package handle authentication?

查看:104
本文介绍了emacs的url如何处理身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有在网络上看到一个很好的例子。如何向如下请求添加身份验证:

 (defun login-show-posts()

(let((url-request-methodGET)
(url-request-extra-headers'((Content-Type。application / xml)))
(url-retrievehttp:// localhost:3000 / essay / 1.xml
(lambda(status)
(switch-to-buffer(current-buffer))
))))

如果例如,用户和pass是admin:admin?

解决方案

我的印象是, url.el 主要用于交互式操作,即您未经授权进行呼叫,服务器将使用403需要授权(正确代码?)状态进行响应,并且 url.el 会向用户查询用户名和密码。



您可以在查看我的代码http://github.com/hdurer/fluiddb .el 我尝试以编程方式进行操作。



基本上,我自己创建了HTTP authorzation标头(base64编码正确格式化的字符串,并添加了正确的标题到 url-request-extra-headers )。
然后在第二步中,我需要向 url-http-handle-authentication 添加建议,以便不要向用户询问传递的凭据是否为可以接受。



这感觉很像强奸 url.el ,但它适用于我,是我唯一的办法可以使它工作。






你的代码看起来像这样:

 (defvar xyz-user-nameadmin)
(defvar xyz-passwordadmin)

(defvar xyz-块授权nil
标记是否阻止url.el的通常的交互授权过程)

(defadvice url-http-handle-authentication(around xyz-fix)
除非xyz-block-authorization
ad-do-it))
(ad-activate'url-http-handle-authentication)


(defun login-
(交互式)
(let((xyz-block-authorization t))
(url-request-methodGET)
(url-request-额外标题
`((内容类型) application / xml)
(授权,(concatBasic
(base64-encode-string
(concat xyz-user-name:xyz-password)) ))))
(url-retrievehttp:// localhost:3000 / essay / 1.xml
(lambda(status)
(switch-to-buffer缓冲区))
))))


I have not seen a really good example on the web. How can I add authentication to a request like this:

(defun login-show-posts ()
  (interactive)
  (let ((url-request-method "GET")
        (url-request-extra-headers '(("Content-Type" . "application/xml"))))
    (url-retrieve "http://localhost:3000/essay/1.xml" 
    (lambda (status)
                    (switch-to-buffer (current-buffer))
                    ))))

if for example, the user and pass is admin:admin?

解决方案

I got the impression that url.el was designed mostly for interactive operations, i.e. you do a call without authorisation, the server responds with a 403 "authorization needed" (correct code?) status and url.el will query the user for user name and password.

You can have a look at my code on http://github.com/hdurer/fluiddb.el where I try to do things programmatically.

Basically, I create the HTTP authorzation header myself (base64 encoding the correctly formatted string and adding the correct header to url-request-extra-headers). Then in a second step I need to add advice to url-http-handle-authentication so that it won't ask the user should the passed credentials not be acceptable.

This feels a lot like raping url.el but it works for me and is the only way I could make it work.


Your code would thus look something like this:

 (defvar xyz-user-name "admin")
 (defvar xyz-password "admin")

 (defvar xyz-block-authorisation nil 
   "Flag whether to block url.el's usual interactive authorisation procedure")

 (defadvice url-http-handle-authentication (around xyz-fix)
   (unless xyz-block-authorisation
       ad-do-it))
 (ad-activate 'url-http-handle-authentication)


 (defun login-show-posts ()
   (interactive)
   (let ((xyz-block-authorisation t)
         (url-request-method "GET")
         (url-request-extra-headers 
          `(("Content-Type" . "application/xml")
            ("Authorization" . ,(concat "Basic "
                                        (base64-encode-string
                                         (concat xyz-user-name ":" xyz-password)))))))
     (url-retrieve "http://localhost:3000/essay/1.xml" 
                   (lambda (status)
                     (switch-to-buffer (current-buffer))
                     ))))

这篇关于emacs的url如何处理身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆