繁体   English   中英

尝试通过 curl 更新 github 分支保护后 HTTP 响应 401

[英]HTTP response 401 after trying to update github branch protection via curl

以下 bash 脚本的目的应该是使用 curl 设置分支保护。 我收到错误 401,我确信我在脚本中使用的凭据是正确的。 授权的设置方式有问题吗? (实际凭据不是从原始脚本中复制的)

#!/bin/bash

OAUTH2_TOKEN=""

OWNER=""
REPO=""

curl https://api.github.com/repos/${OWNER}/${REPO}/branches/main/ \
    -X PUT \
    -H "Authorization: Token ${OAUTH2_TOKEN}" \
    -H "Accept: application/vnd.github+json" \
    -vv \
    -d '{
      "protection": {
        "enabled": true,
        "required_status_checks": {
        "strict": true,
        "contexts": []
          "enforcement_level": "everyone",
          "contexts": [
            "default"
          ]
        }
      }
    }' \
 | json protection 

日志(所有者、回购和代币替换的实际值):


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 140.82.113.6:443...
* TCP_NODELAY set
* Connected to api.github.com (140.82.113.6) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.3 (IN), TLS handshake, Server hello (2):
{ [122 bytes data]
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
{ [19 bytes data]
* TLSv1.3 (IN), TLS handshake, Certificate (11):
{ [2456 bytes data]
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
{ [79 bytes data]
* TLSv1.3 (IN), TLS handshake, Finished (20):
{ [36 bytes data]
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.3 (OUT), TLS handshake, Finished (20):
} [36 bytes data]
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: C=US; ST=California; L=San Francisco; O=GitHub, Inc.; CN=*.github.com
*  start date: Mar 16 00:00:00 2022 GMT
*  expire date: Mar 16 23:59:59 2023 GMT
*  subjectAltName: host "api.github.com" matched cert's "*.github.com"
*  issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS Hybrid ECC SHA384 2020 CA1
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
} [5 bytes data]
* Using Stream ID: 1 (easy handle 0x5560a79d52f0)
} [5 bytes data]
> PUT /repos/owner/repo/branches/main/ HTTP/2
> Host: api.github.com
> user-agent: curl/7.68.0
> authorization: Token ""
> accept: application/vnd.github+json
> content-length: 256
> content-type: application/x-www-form-urlencoded
>
} [5 bytes data]
* We are completely uploaded and fine
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [57 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [57 bytes data]
* old SSL session ID is stale, removing
{ [5 bytes data]
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
} [5 bytes data]
< HTTP/2 401
< server: GitHub.com
< date: Mon, 26 Sep 2022 15:25:24 GMT
< content-type: application/json; charset=utf-8
< content-length: 90
< x-github-media-type: github.v3; format=json
< x-ratelimit-limit: 60
< x-ratelimit-remaining: 59
< x-ratelimit-reset: 1664209524
< x-ratelimit-used: 1
< x-ratelimit-resource: core
< access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< access-control-allow-origin: *
< strict-transport-security: max-age=31536000; includeSubdomains; preload
< x-frame-options: deny
< x-content-type-options: nosniff
< x-xss-protection: 0
< referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
< content-security-policy: default-src 'none'
< vary: Accept-Encoding, Accept, X-Requested-With
< x-github-request-id: 843E:270E:8439F7:10EBE61:6331C464
<
{ [90 bytes data]
100   346  100    90  100   256    273    778 --:--:-- --:--:-- --:--:--  1054
* Connection #0 to host api.github.com left intact

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM