当前位置:   article > 正文

gitlab api Authentication接口身份认证_gitlab oauth2认证

gitlab oauth2认证

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"  } 
  • 1

OAuth2 tokens

您可以通过在access_token参数或Authorization标头中传递OAuth2 令牌来对 API 进行身份验证.

在参数中使用 OAuth2 令牌的示例:

curl "https://gitlab.example.com/api/v4/projects?access_token=OAUTH-TOKEN" 
  • 1

在标头中使用 OAuth2 令牌的示例:

curl --header "Authorization: Bearer OAUTH-TOKEN" "https://gitlab.example.com/api/v4/projects" 
  • 1

阅读有关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>" 
  • 1

在标头中使用个人/项目访问令牌的示例:

curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects" 
  • 1

您还可以将个人/项目访问令牌与 OAuth 兼容标头一起使用:

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

参考链接:https://static.kancloud.cn/apachecn/gitlab-doc-zh/1948860

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/208038
推荐阅读
相关标签
  

闽ICP备14008679号