{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/zh/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["img"]},"type":"markdown"},"seo":{"title":"认证","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"认证","__idx":0},"children":["认证"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["MoreLogin 为其两种 API 类型使用不同的身份验证方法。"]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"本地api认证","__idx":1},"children":["本地API认证"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["本地 API 在 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["http://127.0.0.1:40000"]}," 上运行，并且只能从本地计算机访问。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"默认模式无身份验证","__idx":2},"children":["默认模式（无身份验证）"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["默认情况下，本地API不需要身份验证。您可以直接提出请求："]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -X POST http://127.0.0.1:40000/api/env/page \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"pageNo\": 1,\n    \"pageSize\": 10\n  }'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"启用身份验证","__idx":3},"children":["启用身份验证"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["为了增强安全性，您可以在 MoreLogin 客户端中启用本地 API 身份验证："]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["打开 MoreLogin 客户端"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["导航至 ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["设置"]}," → ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["API 和 MCP"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["启用",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["本地 API 身份验证"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["复制生成的授权令牌"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/image.590455fe8c04c7aec45454ddba2524af46ee8128e15fbef43221c071f4863f91.bb1479e6.png","alt":"启用本地 API 身份验证"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["启用后，在所有请求中包含 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Authorization"]}," 标头："]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -X POST http://127.0.0.1:40000/api/env/page \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: YOUR_AUTH_TOKEN\" \\\n  -d '{\n    \"pageNo\": 1,\n    \"pageSize\": 10\n  }'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"blockquote","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["安全说明"]},"：本地 API 仅在 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["localhost"]}," 上可用。无法远程访问它。"]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"开放-api-身份验证-oauth2","__idx":4},"children":["开放 API 身份验证 (OAuth2)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Open API 使用 OAuth2 客户端凭据流来验证请求。"]},{"$$mdtype":"Tag","name":"blockquote","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["打开 API 服务器端点：",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["https://api.morelogin.com"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"第1步获取api-id和api密钥","__idx":5},"children":["第1步：获取API ID和API密钥"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["打开 MoreLogin 客户端"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["导航至 ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["设置"]}," → ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["API 和 MCP"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["复制 ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["API ID"]}," 和 ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["API 密钥"]}]}]},{"$$mdtype":"Tag","name":"Image","attributes":{"src":"/assets/image.5fd3488a120b7d8e2f400229cb0ad75e34ad8299fa6cfc9c304c29662ff9ade1.30e7cde8.png","alt":"API ID 和密钥","framed":false,"withLightbox":true,"width":"","height":""},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"第-2-步获取访问令牌","__idx":6},"children":["第 2 步：获取访问令牌"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["将您的 API ID 和 API 密钥交换为访问令牌："]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -X POST https://api.morelogin.com/oauth2/token \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"client_id\": \"YOUR_API_ID\",\n    \"client_secret\": \"YOUR_API_KEY\",\n    \"grant_type\": \"client_credentials\"\n  }'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["响应示例："]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"{\n    \"code\": 0,\n    \"msg\": null,\n    \"data\": {\n        \"scope\": \"cloudphone\",\n        \"access_token\": \"eyJ0eXAiOiJKV1QiLCJhbGciOi...\",\n        \"token_type\": \"Bearer\",\n        \"expires_in\": 3600,\n        \"client_metadata\": {\n            \"name\": \"Example Team\"\n        }\n    },\n    \"requestId\": \"4b727b1d53a445d0a46389465b562360\"\n}\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"第-3-步使用访问令牌","__idx":7},"children":["第 3 步：使用访问令牌"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["将访问令牌包含在所有 Open API 请求的 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Authorization"]}," 标头中："]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"curl -X POST https://api.morelogin.com/cloudphone/app/page \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer YOUR_ACCESS_TOKEN\" \\\n  -d '{\n    \"pageNum\": 1,\n    \"pageSize\": 10\n  }'\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"blockquote","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["注意"]},"：访问令牌将在 ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["3600 秒"]},"（1 小时）后过期。当前令牌到期时请求新令牌。"]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"认证比较","__idx":8},"children":["认证比较"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"特点"},"children":["特点"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"本地API"},"children":["本地API"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"开放API"},"children":["开放API"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["方法"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["静态令牌（可选）"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["OAuth2 访问令牌"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["令牌生命周期"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["永久（直到再生）"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["1小时"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["去哪获取"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["MoreLogin 客户端设置"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["交换 API ID + 密钥"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["标题格式"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Authorization: TOKEN"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Authorization: Bearer TOKEN"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["必填"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["可选（可以禁用）"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["始终需要"]}]}]}]}]}]},"headings":[{"value":"认证","id":"认证","depth":1},{"value":"本地API认证","id":"本地api认证","depth":2},{"value":"默认模式（无身份验证）","id":"默认模式无身份验证","depth":3},{"value":"启用身份验证","id":"启用身份验证","depth":3},{"value":"开放 API 身份验证 (OAuth2)","id":"开放-api-身份验证-oauth2","depth":2},{"value":"第1步：获取API ID和API密钥","id":"第1步获取api-id和api密钥","depth":3},{"value":"第 2 步：获取访问令牌","id":"第-2-步获取访问令牌","depth":3},{"value":"第 3 步：使用访问令牌","id":"第-3-步使用访问令牌","depth":3},{"value":"认证比较","id":"认证比较","depth":2}],"frontmatter":{"seo":{"title":"认证"}},"lastModified":"2026-06-10T11:47:34.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/zh/api-reference/getting-started/authentication","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}