JIRA REST API Example - Cookie-based Authentication
2016-04-20 11:30
429 查看
三种方式可以通过 JIRA REST API 授权:allow REST clients to authenticate themselves using
1. cookies
2. basic authentication.
3. OAuth
当然此次主要是面向 cookie-based——存在一定的风险:
“
*reference
Your session cookies can be hijacked if handled improperly.This document does not go into the security implications of cookies,but if you should make yourself aware of the risks, before considering this approach.
”
在使用 cookie 前你需要知道的:
“
*reference
The basics of using REST APIs, e.g. requests, responses, headers.
The basics of using and administering JIRA.
”
实际上通过 cooki-based 来授权就需要三步:
“
*reference
This is how cookie-based authentication works in JIRA at a high level:
The client creates a new session for the user, via the JIRA REST API .
JIRA returns a session object, which has information about the session including the session cookie. The client stores this session object.
The client can now set the cookie in the header for all subsequent requests to the JIRA REST API.
”
1. 通过 JIRA REST API (实际上就是一个 url,不过是根据你所在的项目定制的)创建好一个session。
2. 将得到的 session 对象(session 对象里面包含 cookie 信息)返回。
- session 对象大致长成这样:
“
*reference
{
"session":
{
"name":"JSESSIONID",
"value":"6E3487971234567896704A9EB4AE501F"
},
"loginInfo":
{
"failedLoginCount":1,
"loginCount":2,
"lastFailedLoginTime":"2013-11-27T09:43:28.839+0000",
"previousLoginTime":"2013-12-04T07:54:59.824+0000"
}
}
”
3. 将 cookie 设置到 headers 里面。
具体的步骤:
第一步:通过 JIRA REST API 创建 session
“
*reference
To do this, just POST the desired user credentials (as JSON) to the session resource:
Example resource http://jira.example.com:8090/jira/rest/auth/1/session
Example credentials { "username": "myuser", "password": "mypassword" }
”
使用 post 方式将 上述的 credentials 中的内容转换为 json (Python:使用 json.dumps()方法 )类型,然后将其 post 到需要的 resource (例如:http://hdc-tomcat-xxx.xxxxsoft.org/jira/rest/auth/1/session)里面。
第二步:将session对象的cookie 信息提取出来,当你需要发送请求的时候,从session 中提取出 cookie 的 name + value——session 关键字里面的 name/value 关键字。
1. cookies
2. basic authentication.
3. OAuth
当然此次主要是面向 cookie-based——存在一定的风险:
“
*reference
Your session cookies can be hijacked if handled improperly.This document does not go into the security implications of cookies,but if you should make yourself aware of the risks, before considering this approach.
”
在使用 cookie 前你需要知道的:
“
*reference
The basics of using REST APIs, e.g. requests, responses, headers.
The basics of using and administering JIRA.
”
实际上通过 cooki-based 来授权就需要三步:
“
*reference
This is how cookie-based authentication works in JIRA at a high level:
The client creates a new session for the user, via the JIRA REST API .
JIRA returns a session object, which has information about the session including the session cookie. The client stores this session object.
The client can now set the cookie in the header for all subsequent requests to the JIRA REST API.
”
1. 通过 JIRA REST API (实际上就是一个 url,不过是根据你所在的项目定制的)创建好一个session。
2. 将得到的 session 对象(session 对象里面包含 cookie 信息)返回。
- session 对象大致长成这样:
“
*reference
{
"session":
{
"name":"JSESSIONID",
"value":"6E3487971234567896704A9EB4AE501F"
},
"loginInfo":
{
"failedLoginCount":1,
"loginCount":2,
"lastFailedLoginTime":"2013-11-27T09:43:28.839+0000",
"previousLoginTime":"2013-12-04T07:54:59.824+0000"
}
}
”
3. 将 cookie 设置到 headers 里面。
具体的步骤:
第一步:通过 JIRA REST API 创建 session
“
*reference
To do this, just POST the desired user credentials (as JSON) to the session resource:
Example resource http://jira.example.com:8090/jira/rest/auth/1/session
Example credentials { "username": "myuser", "password": "mypassword" }
”
使用 post 方式将 上述的 credentials 中的内容转换为 json (Python:使用 json.dumps()方法 )类型,然后将其 post 到需要的 resource (例如:http://hdc-tomcat-xxx.xxxxsoft.org/jira/rest/auth/1/session)里面。
第二步:将session对象的cookie 信息提取出来,当你需要发送请求的时候,从session 中提取出 cookie 的 name + value——session 关键字里面的 name/value 关键字。
相关文章推荐
- hadoop参考资料
- Linux Yum 命令使用举例(很全很实用)
- @Autowired 与@Resource的区别:
- robotframework笔记17
- source insight项目文件列表固定嵌入右侧
- MySQL入门很简单: 15 java访问MySQL数据库
- 5分钟 搭建免费个人博客
- mysql
- Could not alter table in Spark 1.5 use HiveContext
- Python 的数据结构
- Xcode模拟器出现installation failed invalid argument
- NTFS会对游戏运行有不良影响吗?
- xlrd 读取excel日期,时间 方法 转(stackoverflow)
- 数据库列名使用了关键字怎么办?
- volatile小记
- Android实现多次闪退清除数据
- opensuse42.1软件源
- bzoj 4262: Sum
- Java小程序之判断输入年份是否是闰年
- Android6. 4000 0找不到org.apache.http.Header的问题(转)