[英]login to jenkins using ajax/javascript
I want to run a Jenkis job that requires login from a web page (outside of jenkins) using ajax currenly i have to have another browser tab with jenkins open (and authenticated) in order for the job to run from my web page 我想运行一个Jenkis工作,需要使用ajax从网页(jenkins之外)登录,当前我必须有另一个浏览器选项卡,jenkins打开(并通过身份验证),以便从我的网页运行作业
iv'e tried different approaches to sending the authentication info with ajax this is what i currently have: iv'e尝试了使用ajax发送身份验证信息的不同方法,这就是我目前所拥有的:
$.ajax({
type: "POST",
url: "http://myjenkins/job/job_name/buildWithParameters",
dataType: 'jsonp',
data: $("#myForm").serialize(),
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization", "username:password");
},
success: function(data) {
},
complete: function(xhr, statusText){
}
});
(there's some more HTML code that receives parameters from a form) if i have an open tab with jenkins authenticated this runs fine, but if i don't i get a "430 forbidden" responce from jenkins. (还有一些HTML代码从表单接收参数)如果我有一个打开的标签,jenkins经过身份验证,运行正常,但如果我不这样做,我会得到jenkins的“430禁止”响应。
the "xhr.setRequestHeader("Authorization", "username:password");" “xhr.setRequestHeader(”授权“,”用户名:密码“);” is just my latest attempt...
这只是我最近的尝试......
any input is welcome! 欢迎任何输入!
beforeSend: function (xhr) {
xhr.withCredentials = true;
data: $("[name='parameters']").serialize()
xhr.setRequestHeader("Authorization", "Basic " + btoa("test:d8db6ae61f03219c52042638488e9744"));
},
works for me 适合我
This worked for me, thanks a lot, just to expand, it worked because As per RFC 1945, the Authorization header value should contain the username:password as encoded (base64) string, which would result in something like the following header: 这对我很有用,非常感谢,只是为了扩展,它起作用了,因为根据RFC 1945,Authorization标头值应该包含用户名:password as encoded(base64)string,这将导致类似以下标题:
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 授权:基本QWxhZGRpbjpvcGVuIHNlc2FtZQ ==
example: 例:
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("username:token"));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.