gitlab api中的MR身份验证

时间:2019-04-05 03:58:59

标签: git authentication gitlab gitlab-api

上下文:

作为某些项目的一部分,我必须获取MR的所有详细信息(目录结构/ + 1s /注释分辨率等)。以后还必须根据某些条件将其合并。

所有这些操作都是通过第三方应用程序完成的,该应用程序可以访问将在其中生成MR的gitlab分支

问题区域

经历API documentation时,我试图获取MR,但是每次我访问登录身份验证页面时(即使添加了Personal Access Token之后)

In [14]: url_value
Out[14]: "https://gitlab.our_custom_domain.com/projects/frontend-services/major_repo/merge_requests/11/?private_token='DcpikqosHCyZAstyzXBQ'"

In [15]: requests.get(url_value).text
Out[15]: '<!DOCTYPE html>\n<html class="devise-layout-html">\n<head prefix="og: http://ogp.me/ns#">\n<meta charset="utf-8">\n<meta content="IE=edge" http-equiv="X-UA-Compatible">\n<meta content="object" property="og:type">\n<meta content="GitLab" property="og:site_name">\n<meta content="Sign in" property="og:title">\n<meta content="GitLab Community Edition" property="og:description">\n<meta content="https://gitlab.our_custom_domain.com/assets/gitlab_logo-7ae504fe4f68fdebb3c2034e36621930cd36ea87924c11ff65dbcb8ed50dca58.png" property="og:image">\n<meta content="64" property="og:image:width">\n<meta content="64" property="og:image:height">\n<meta content="https://gitlab.our_custom_domain.com/users/sign_in" property="og:url">\n<meta content="summary" property="twitter:card">\n<meta content="Sign in" property="twitter:title">\n<meta content="GitLab Community Edition" property="twitter:description">\n<meta content="https://gitlab.our_custom_domain.com/assets/gitlab_logo-7ae504fe4f68fdebb3c2034e36621930cd36ea87924c11ff65dbcb8ed50dca58.png" property="twitter:image">\n\n<title>Sign in · GitLab</title>\n<meta content="GitLab Community Edition" name="description">\n<link rel="shortcut icon" type="image/png" href="/assets/favicon-7901bd695fb93edb07975966062049829afb56cf11511236e61bcf425070e36e.png" id="favicon" data-original-href="/assets/favicon-7901bd695fb93edb07975966062049829afb56cf11511236e61bcf425070e36e.png" />\n<link rel="stylesheet" media="all" href="/assets/application-3699df5421217cf3678b3fccba46be0eb9ba5f72488c2eece3cf7ee2e8e8b284.css" />\n<link rel="stylesheet" media="print" href="/assets/print-c8ff536271f8974b8a9a5f75c0ca25d2b8c1dceb4cff3c01d1603862a0bdcbfc.css" />\n\n\n<script>\n//<![CDATA[\nwindow.gon={};gon.api_version="v4";gon.default_avatar_url="https://gitlab.our_custom_domain.com/assets/no_avatar-849f9c04a3a0d0cea2424ae97b27447dc64a7dbfae83c036c45b403392f0e8ba.png";gon.max_file_size=10;gon.asset_host=null;gon.webpack_public_path="/assets/webpack/";gon.relative_url_root="";gon.shortcuts_path="/help/shortcuts";gon.user_color_scheme="white";gon.gitlab_url="https://gitlab.our_custom_domain.com";gon.revision="35936b0";gon.gitlab_logo="/assets/gitlab_logo-7ae504fe4f68fdebb3c2034e36621930cd36ea87924c11ff65dbcb8ed50dca58.png";gon.sprite_icons="/assets/icons-07542808fffaf82e9b57b144464ea42620b32f65ce441c01528d23d4b96d5f11.svg";gon.sprite_file_icons="/assets/file_icons-7262fc6897e02f1ceaf8de43dc33afa5e4f9a2067f4f68ef77dcc87946575e9e.svg";gon.emoji_sprites_css_path="/assets/emoji_sprites-289eccffb1183c188b630297431be837765d9ff4ae
.....
.....
.....
.....

问题:

使用gitlab API时如何验证请求?

1 个答案:

答案 0 :(得分:2)

GitLab API

中所述
  

您可以通过在private_token参数或Private-Token标头中传递个人访问令牌来使用该API进行身份验证。

     

在参数中使用个人访问令牌的示例:

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

在您的情况下:

merge_requests/11/?private_token='DcpikqosHCyZAstyzXBQ'"

请勿在PAT(个人访问令牌)周围使用简单的引号

merge_requests/11/?private_token=DcpikqosHCyZAstyzXBQ