0
点赞
收藏
分享

微信扫一扫

gitlab api Authentication接口身份认证


Authentication

大多数 API 请求都需要身份验证,或者仅在不提供身份验证时才返回公共数据. 对于不需要的情况,将在文档中针对每个端点进行提及. 例如, ​​/projects/:id端点​​ .

使用 GitLab API 进行身份验证的方法有几种:

  1. ​​OAuth2 tokens​​
  2. ​​Personal access tokens​​
  3. ​​Project access tokens​​
  4. ​​Session cookie​​
  5. ​​GitLab CI/CD job token​​(仅特定端点)

对于想要以特定用户身份向 API 进行身份验证的管理员,或者想要构建执行此操作的应用程序或脚本的管理员,可以使用以下两种方法:

  1. ​​Impersonation tokens​​
  2. ​​Sudo​​

如果身份验证信息无效或被忽略,将返回一条错误消息,状态码为​​401​​ :

{  "message":  "401 Unauthorized"  } 

OAuth2 tokens

您可以通过在​​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 提供程序的​​更多信息.

Personal/project access tokens

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​​


举报

相关推荐

0 条评论