Help us learn about your current experience with the documentation. Take the survey.

应用程序 API

  • 版本:Free, Premium, Ultimate
  • 产品形态:GitLab Self-Managed, GitLab Dedicated

使用此 API 与实例范围的 OAuth 应用程序进行交互,适用于以下场景:

您不能使用此 API 来管理组应用程序或个人用户应用程序。

前提条件:

  • 您必须拥有该实例的管理员访问权限。

创建应用程序

通过发送 JSON 负载来创建应用程序。

如果请求成功,将返回 200

POST /applications

支持的属性:

属性 类型 必需 描述
name string 应用程序的名称。
redirect_uri string 应用程序的重定向 URI。
scopes string 应用程序的权限范围。您可以通过空格分隔来指定多个范围。
confidential boolean 此应用程序用于能够安全保管客户端密钥的场景。原生移动应用和单页应用 (SPA) 则被视为非机密应用。如果未提供此参数,则默认为 true

请求示例:

curl --request POST \
    --header "PRIVATE-TOKEN: <your_access_token>" \
    --data "name=MyApplication&redirect_uri=http://redirect.uri&scopes=api read_user email" \
    --url "https://gitlab.example.com/api/v4/applications"

响应示例:

{
    "id":1,
    "application_id": "5832fc6e14300a0d962240a8144466eef4ee93ef0d218477e55f11cf12fc3737",
    "application_name": "MyApplication",
    "secret": "ee1dd64b6adc89cf7e2c23099301ccc2c61b441064e9324d963c46902a85ec34",
    "callback_url": "http://redirect.uri",
    "confidential": true
}

列出所有应用程序

列出所有已注册的应用程序。

GET /applications

请求示例:

curl --request GET \
    --header "PRIVATE-TOKEN: <your_access_token>" \
    --url "https://gitlab.example.com/api/v4/applications"

响应示例:

[
    {
        "id":1,
        "application_id": "5832fc6e14300a0d962240a8144466eef4ee93ef0d218477e55f11cf12fc3737",
        "application_name": "MyApplication",
        "callback_url": "http://redirect.uri",
        "confidential": true
    }
]

此 API 不会暴露 secret 的值。

删除应用程序

删除指定的应用程序。

如果请求成功,将返回 204

DELETE /applications/:id

支持的属性:

属性 类型 必需 描述
id integer 应用程序的 ID(不是 application_id)。

请求示例:

curl --request DELETE \
    --header "PRIVATE-TOKEN: <your_access_token>" \
    --url "https://gitlab.example.com/api/v4/applications/:id"

更新应用程序密钥

更新应用程序的密钥。如果请求成功,将返回 200

POST /applications/:id/renew-secret

支持的属性:

属性 类型 必需 描述
id integer 应用程序的 ID(不是 application_id)。

请求示例:

curl --request POST \
    --header "PRIVATE-TOKEN: <your_access_token>" \
    --url "https://gitlab.example.com/api/v4/applications/:id/renew-secret"

响应示例:

{
    "id":1,
    "application_id": "5832fc6e14300a0d962240a8144466eef4ee93ef0d218477e55f11cf12fc3737",
    "application_name": "MyApplication",
    "secret": "ee1dd64b6adc89cf7e2c23099301ccc2c61b441064e9324d963c46902a85ec34",
    "callback_url": "http://redirect.uri",
    "confidential": true
}