{{< details >}}

  • Tier: 基础版, 专业版, 旗舰版
  • Offering: 私有化部署

{{< /details >}}

使用此 API 与实例范围的 OAuth 应用程序交互:

{{< alert type=”note” >}}

您无法使用此 API 管理群组应用程序或个人用户应用程序。

{{< /alert >}}

先决条件:

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

创建一个应用程序

通过发送 JSON 数据负载来创建一个应用程序。

如果请求成功,则返回 200

POST /applications

支持的属性:

属性 类型 是否必须 描述
name string 应用程序的名称。
redirect_uri string 应用程序的重定向 URI。
scopes string 应用程序的范围。您可以通过空格分隔每个范围来指定多个范围。
confidential boolean 应用程序用于客户端密钥可以保密的地方。原生移动应用程序和单页应用程序被认为是非保密的。如果未提供,默认为 true

示例请求:

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

示例响应:

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

{{< alert type=”note” >}}

此 API 不会公开 secret 值。

{{< /alert >}}

删除一个应用程序

删除特定的应用程序。

如果请求成功,则返回 204

DELETE /applications/:id

支持的属性:

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

示例请求:

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

更新应用程序密钥

{{< history >}}

  • 引入于极狐GitLab 16.11。

{{< /history >}}

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

POST /applications/:id/renew-secret

支持的属性:

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

示例请求:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "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
}