beberlei / tent-php
PHP 应用客户端,用于 Tent.io 协议
dev-master
2013-02-09 14:23 UTC
This package is auto-updated.
Last update: 2024-09-12 03:38:44 UTC
README
PHP 的 Tent 客户端 API
Tent.io 是一种用于社交网络的分布式协议。它包括 tent 服务器和 tent 应用程序。用户在 tent 服务器上托管他们的数据。tent 应用程序可以修改这些数据。要实现 tent 应用程序,你需要一个客户端。这个库提供了一个用 PHP 编写的客户端。
客户端必须充当一个应用程序,以便能够访问任何 tent 服务器上的用户详情。为了工作,应用程序通常需要维护有关 Tent 服务器 URL 以及它们的 OAuth 客户端 ID 和 Mac 密钥的一定程度的状态。
特性
- 支持 Tent.io 应用程序 API
- 在任何 tent 服务器上自动注册应用程序
- 应用程序和用户授权的持久性(MAC 认证)
状态 & 持久性
此应用程序状态隐藏在持久化接口 TentPHP\Persistence\ApplicationState
后。我们提供基于 Doctrine DBAL 的实现。
其他客户端(PHP + 其他语言)将持久化的负担放在你身上,从它们的方法返回所有有状态的数据。使用 ApplicationState
接口,你可以自行实现它,或使用我们的 Doctrine 后端。在任何情况下,这都大大简化了客户端的使用。
安装
使用 Composer 安装 TentPHP 及其所有依赖项
{ "require": { "beberlei/tent-php": "*", "doctrine/dbal": "*" } }
API(使用 Doctrine DBAL)
设置 & 配置
<?php use TentPHP\Application; use TentPHP\Client; use TentPHP\PhpSessionState; use TentPHP\DBAL\DoctrineUserStorage; use Doctrine\DBAL\DriverManager; use Guzzle\Http\Client as HttpClient; $application = new Application(array( "name" => "FooApp", "description" => "Does amazing foos with your data", "url" => "http =>//example.com", "icon" => "http =>//example.com/icon.png", "redirect_uris" => array( "https =>//app.example.com/tent/callback" ), "scopes" => array( "write_profile" => "Uses an app profile section to describe foos", "read_followings" => "Calculates foos based on your followings" ) )); $conn = DriverManager::getConnection(array( 'driver' => 'pdo_mysql', 'host' => 'localhost', 'dbname' => 'tentclient', 'username' => 'user', 'password' => 'pw', )); $encryptionKey = "abcdef12345"; DoctrineUserStorage::registerTentEncryptionStringType($encryptionKey); $userStorage = new DoctrineUserStorage($conn); $state = new PhpSessionState(); $client = new Client($application, $httpClient, $userStorage, $state);
请求用户登录 URL
$loginUrl = $client->getLoginUrl('https://beberlei.tent.is'); header("Location: " . $loginUrl);
OAuth 授权后授权
$client->authorize($_GET['state'], $_GET['code']);
获取 UserClient
$user = $client->getUserClient('https://beberlei.tent.is');