Gitlhub访问令牌不工作“$GITLAB\u AUTH\u令牌

2024-05-15 10:21:45 发布

您现在位置:Python中文网/ 问答频道 /正文

希望有人能在这方面帮助我。 我在.SH中编写了一个API来获取消息的详细信息

curl --silent -k --header "PRIVATE-TOKEN:$GITLAB_AUTH_TOKEN"** *and some code*

在这里,当硬编码PRIVATE-TOKEN时,脚本工作正常,但是当我使用这个变量时,它就不工作了

有人能提出为什么会发生这种情况以及可能的解决办法吗


Tags: andtokenauthapi消息编码shgitlab
1条回答
网友
1楼 · 发布于 2024-05-15 10:21:45

我首先检查变量是否设置正确:

echo "GITLAB_AUTH_TOKEN='${GITLAB_AUTH_TOKEN}'"

请注意${GITLAB_AUTH_TOKEN}周围的简单引号:它有助于可视化标记后面是否有多余的空间,这可能会有问题

为了安全起见,我将使用${}语法:

curl  silent -k  header "PRIVATE-TOKEN: ${GITLAB_AUTH_TOKEN}"

我还将对 verbose而不是 silent执行相同的命令,以便查看curl正在做什么(用于测试)

注意PRIVATE-TOKEN:和标记之间的空格。
GitLab API / Personal/project access tokens

Example of using the personal or project access token in a parameter:

curl "https://gitlab.example.com/api/v4/projects?private_token=<your_access_token>"

Example of using the personal or project access token in a header:

curl  header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects"

You can also use personal or project access tokens with OAuth-compliant headers:

curl  header "Authorization: Bearer <your_access_token>" "https://gitlab.example.com/api/v4/projects"

相关问题 更多 >