# 提交 MCP OAuth 授权决定

浏览器授权页提交同意或拒绝，服务跳转到已注册回调。

POST `/oauth/authorize`

- **认证** 控制台会话 Cookie。
- **成功状态** `303`

## 请求参数

| 参数 | 类型 | 位置 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| `Origin` | URI | `header` | 是 | 当前站点的完整来源。 |
| `request` | string | `body` | 是 | 浏览器授权页的待确认申请值。 |
| `csrf` | string | `body` | 是 | 浏览器授权页中和当前会话绑定的表单值。 |
| `action` | approve \| deny | `body` | 是 | 用户在授权界面作出的决定。 |

## 请求示例

JavaScript 示例可在本站已登录的浏览器中运行。cURL 和 Python 示例读取你本机的 cookies.txt Cookie 文件。请将会话 Cookie 视为私密凭据。

**cURL**

```bash
curl -i -X POST 'https://social2api.com/oauth/authorize' \
  --cookie ./cookies.txt \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Origin: https://social2api.com' \
  --data-binary 'request=%3Cpending+request%3E&csrf=%3Cconsent+form+value%3E&action=approve'
```

**Python**

```python
from urllib.error import HTTPError
from urllib.request import Request, HTTPCookieProcessor, build_opener
from http.cookiejar import MozillaCookieJar

request = Request(
    "https://social2api.com/oauth/authorize",
    method="POST",
    headers={
        "Content-Type": "application/x-www-form-urlencoded",
        "Origin": "https://social2api.com",
    },
    data="request=%3Cpending+request%3E&csrf=%3Cconsent+form+value%3E&action=approve".encode("utf-8"),
)
cookies = MozillaCookieJar("./cookies.txt")
cookies.load(ignore_discard=True)
send = build_opener(HTTPCookieProcessor(cookies)).open
try:
    with send(request) as response:
        print(response.status, response.read().decode("utf-8"))
except HTTPError as error:
    print(error.code, error.read().decode("utf-8"))
```

**JavaScript**

```javascript
const response = await fetch("/oauth/authorize", {
  method: "POST",
  credentials: "same-origin",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded",
  },
  body: new URLSearchParams({
    "request": "<pending request>",
    "csrf": "<consent form value>",
    "action": "approve"
  }),
});
console.log(response.status, await response.text());
```

## 响应

**303 · 示例响应**

无响应正文

**错误示例**

```json
{
  "error": "invalid_request",
  "error_description": "The request is invalid."
}
```

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `Location` | URI | 已注册的回调地址。包含 code 或 error=access\_denied、原 state（如有）和 iss。 |

## 错误状态

| HTTP | 原因与处理 |
| --- | --- |
| `400` | OAuth 请求、范围、资源或表单参数无效。 |
| `401` | 控制台会话缺失、过期或无效。 |
| `403` | 浏览器来源校验未通过。 |
| `405` | 请求方法不受支持。 |
| `500` | 授权服务暂时不可用。 |

## 使用细节

-   写请求须包含与站点完全相同的 Origin。
-   使用当前会话的浏览器授权表单。表单体最多 8,192 字节。授权码只能兑换一次，2 分钟后过期。

## 同组接口

-   [GET 检查数据源配置](<https://social2api.com/docs/api/status/>)
-   [POST 运行取数任务](<https://social2api.com/docs/api/run/>)
-   [POST 调用 MCP 服务](<https://social2api.com/docs/api/mcp/>)
-   [GET 读取 OAuth 授权服务元数据](<https://social2api.com/docs/api/oauth-server-metadata/>)
-   [GET 读取 OAuth 受保护资源元数据](<https://social2api.com/docs/api/oauth-resource-metadata/>)
-   [GET 读取 MCP 资源的 OAuth 元数据](<https://social2api.com/docs/api/oauth-mcp-metadata/>)
-   [POST 注册 MCP OAuth 客户端](<https://social2api.com/docs/api/oauth-register/>)
-   [GET 启动 MCP OAuth 授权](<https://social2api.com/docs/api/oauth-authorize-start/>)
-   [POST 兑换或刷新 MCP OAuth 令牌](<https://social2api.com/docs/api/oauth-token/>)

规范页面：<https://social2api.com/docs/api/oauth-authorize-consent/>
