接入教程
1. 在 1Password 官网注册并创建团队账户
2. 在控制台生成 API 令牌和服务器密钥
3. 安装 1Password Connect 服务器并配置环境变量
4. 使用 REST 客户端测试 API 端点连接
5. 在应用程序中集成 API 调用代码
6. 测试密码检索和存储功能
Python:获取项目列表
import requests
url = "https://api.example.com/v1/items"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
items = response.json()
print(f"Found {len(items)} items")
else:
print(f"Error: {response.status_code}", response.text)
PHP:创建新项目
<?php
$url = "https://api.example.com/v1/items";
$apiKey = "YOUR_API_KEY";
$data = [
"title" => "New Secure Item",
"category" => "LOGIN",
"fields" => []
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $apiKey,
"Content-Type: application/json"
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 201) {
echo "Item created successfully.";
} else {
echo "Error: " . $httpCode . " - " . $response;
}
?>
JavaScript:搜索项目
const fetch = require('node-fetch');
const url = "https://api.example.com/v1/items?query=searchTerm";
const apiKey = "YOUR_API_KEY";
fetch(url, {
method: 'GET',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log(`Search results: ${data.length} items found`);
})
.catch(error => {
console.error('Fetch error:', error);
});
常见问题
1Password Connect API 是否需要付费?
1Password Connect 本身是 1Password 企业版和团队版的一部分,通常需要订阅相应的 1Password 商业计划。API 调用本身不额外收费,但需要使用有效的 1Password 账户和授权。
API 密钥如何获取?
API 密钥(通常以令牌形式)需要在 1Password 管理控制台中生成。管理员可以创建具有特定权限的访问令牌,用于通过 Connect 服务器进行身份验证。请勿在客户端代码中硬编码令牌。
API 支持哪些数据操作?
1Password Connect API 支持对保险库、项目、字段进行完整的 CRUD 操作,包括创建、读取、更新、删除密码、安全备注、信用卡信息等敏感数据,以及搜索和筛选项目。
Aitishiku.com