赞
踩
大多数 API 请求都需要身份验证,或者仅在不提供身份验证时才返回公共数据. 对于不需要的情况,将在文档中针对每个端点进行提及. 例如, /projects/:id
端点 .
使用 GitLab API 进行身份验证的方法有几种:
对于想要以特定用户身份向 API 进行身份验证的管理员,或者想要构建执行此操作的应用程序或脚本的管理员,可以使用以下两种方法:
如果身份验证信息无效或被忽略,将返回一条错误消息,状态码为401
:
{ "message": "401 Unauthorized" }
您可以通过在access_token
参数或Authorization
标头中传递OAuth2 令牌来对 API 进行身份验证.
在参数中使用 OAuth2 令牌的示例:
curl "https://gitlab.example.com/api/v4/projects?access_token=OAUTH-TOKEN"
在标头中使用 OAuth2 令牌的示例:
curl --header "Authorization: Bearer OAUTH-TOKEN" "https://gitlab.example.com/api/v4/projects"
阅读有关GitLab 作为 OAuth2 提供程序的更多信息.
Access tokens can be used to authenticate with the API by passing it in either the private_token
parameter or the Private-Token
header.
在参数中使用个人/项目访问令牌的示例:
curl "https://gitlab.example.com/api/v4/projects?private_token=<your_access_token>"
在标头中使用个人/项目访问令牌的示例:
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects"
您还可以将个人/项目访问令牌与 OAuth 兼容标头一起使用:
curl --header "Authorization: Bearer <your_access_token>" "https://gitlab.example.com/api/v4/projects"
参考链接:https://static.kancloud.cn/apachecn/gitlab-doc-zh/1948860
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。