Authorization Basic认证 笔记

Basic认证

Basic认证过程简单介绍

  1. 浏览器请求一个需要认证的网页。
  2. 服务器向浏览器返回“401 Unauthorized(未认证)”状态码。
  3. 浏览器收到此状态码后,询问用户名和密码。
  4. 浏览器发送附带认证信息(Authorization头信息)的请求。
  5. 本次请求得到了文档(用户名密码均正确的情况下)。

方案1: header 添加 Authorization

原理说明:

string code = ‘fozzie:fozzie’
string base = base64(code)
// base. === Zm96emllOmZvenppZQ==

操作命令

请求时添加 Authorization: Basic Zm96emllOmZvenppZQ==

➜  activiti-rest curl  -H 'Authorization: Basic Zm96emllOmZvenppZQ==' -v http://localhost:8080/activiti-rest/service/repository/deployments
操作结果
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /activiti-rest/service/repository/deployments HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.1
> Accept: */*
> Authorization: Basic Zm96emllOmZvenppZQ==
>
< HTTP/1.1 200
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Wed, 23 Feb 2022 09:29:52 GMT
<
* Connection #0 to host localhost left intact
{"data":[{"id":"20","name":"Demo processes","deploymentTime":"2022-02-23T16:00:15.025+08:00","category":null,"url":"http://localhost:8080/activiti-rest/service/repository/deployments/20","tenantId":""}],"total":1,"start":0,"sort":"id","order":"asc","size":1}* Closing connection 0

方案2: 明文直接传输

http://fozzie:fozzie@localhost:8080/activiti-rest/service/repository/deployments

操作命令
➜  activiti-rest curl -v http://fozzie:fozzie@localhost:8080/activiti-rest/service/repository/deployments
操作结果


*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
* Server auth using Basic with user 'fozzie'
> GET /activiti-rest/service/repository/deployments HTTP/1.1
> Host: localhost:8080
> Authorization: Basic Zm96emllOmZvenppZQ==
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Wed, 23 Feb 2022 09:28:20 GMT
<
* Connection #0 to host localhost left intact
{"data":[{"id":"20","name":"Demo processes","deploymentTime":"2022-02-23T16:00:15.025+08:00","category":null,"url":"http://localhost:8080/activiti-rest/service/repository/deployments/20","tenantId":""}],"total":1,"start":0,"sort":"id","order":"asc","size":1}

Jenkins

获取 APIToken

Authorization Basic认证 笔记_第1张图片

Curl
curl 'http://xxxxx/hlcop_release_online.tar.gz' --user "username:ApiToken" --output hlcop.tar.gz

curl 'http://xxxxxxxxx/view/jsy/job/jsy-fe-cop/ws/hlcop_release_online.tar.gz' --user "code:11c08920b03c8c27ecf1617f1b419d1ebd" --output hlcop.tar.gz

你可能感兴趣的:(javascript,前端)