启动 MCP OAuth 授权

浏览器验证客户端、回调、请求资源与 PKCE。提交成功后进入登录或授权确认。

GET/oauth/authorize
认证
可选控制台会话 Cookie。
成功状态
303, 200

请求参数

参数类型位置必填说明
client_idstringquery是动态注册得到的客户端标识。
redirect_uriURIquery是须与注册的回调地址一字不差。
response_typecodequery是授权响应类型。
code_challenge_methodS256query是PKCE 的哈希方式。
code_challengestringquery是校验值的 SHA-256 摘要,使用不带填充的 Base64URL。
resourceURIquery是当前服务绝对地址后加 /mcp。
scopemcp:toolsquery否接受 mcp:tools 范围。
statestringquery否客户端设置的随机状态值,最多 1,024 字符,授权结果原样返回。
requeststringquery否从 Location 收到的临时申请值。查看授权页时只传此值。

请求示例

cURL
curl -i -X GET 'https://social2api.com/oauth/authorize?client_id=client_4a5076aa-f9ab-46e6-b383-7b1374392dc4&redirect_uri=https%3A%2F%2Fexample.com%2Foauth%2Fcallback&response_type=code&code_challenge_method=S256&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&resource=https%3A%2F%2Fsocial2api.com%2Fmcp&scope=mcp%3Atools&state=%3Cclient+state%3E'
Python
from urllib.error import HTTPError
from urllib.request import Request, urlopen

request = Request(
    "https://social2api.com/oauth/authorize?client_id=client_4a5076aa-f9ab-46e6-b383-7b1374392dc4&redirect_uri=https%3A%2F%2Fexample.com%2Foauth%2Fcallback&response_type=code&code_challenge_method=S256&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&resource=https%3A%2F%2Fsocial2api.com%2Fmcp&scope=mcp%3Atools&state=%3Cclient+state%3E",
    method="GET",
)
send = urlopen
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
const response = await fetch("/oauth/authorize?client_id=client_4a5076aa-f9ab-46e6-b383-7b1374392dc4&redirect_uri=https%3A%2F%2Fexample.com%2Foauth%2Fcallback&response_type=code&code_challenge_method=S256&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&resource=https%3A%2F%2Fsocial2api.com%2Fmcp&scope=mcp%3Atools&state=%3Cclient+state%3E", {
  method: "GET",
});
console.log(response.status, await response.text());

响应

303 · 示例响应

无响应正文

200 · HTML
<form action="/oauth/authorize" method="post">…</form>
错误示例
{
  "error": "invalid_request",
  "error_description": "The client or exact redirect URI is not registered."
}

request=%3Cauthorization+request%3E · HTTP 200 · 已登录后读取待确认申请,返回浏览器授权页面。

字段类型说明
LocationURI reference开始时指向待确认申请。未登录时指向登录页,登录后返回待确认申请。

错误状态

HTTP原因与处理
400OAuth 请求、范围、资源或表单参数无效。
405请求方法不受支持。
500授权服务暂时不可用。
429请求过多。等待 Retry-After 指定秒数后重试。

使用细节

  • 在浏览器中打开授权地址,使用本次申请的 PKCE 校验值。临时申请有效期 15 分钟。每 IP 每分钟最多发起 40 次。