Giter VIP home page Giter VIP logo

tentphp's Introduction

PHP Tent Client

Tent Client API for PHP

Tent.io is a distributed protocol for social networking. There are tent servers and tent applications. Users host their data on tent servers. Tent applications can modify this data. To implement a tent application you need a client. This library provides a client written in PHP.

The client has to act as an application to be able to access user details on any tent server. to work applications are always required to maintain some level of state about Tent Servers Url and their OAuth Client Ids and Mac Keys.

Features

  • Support for the Tent.io Application API
  • Automatic registration of Applications on any tent-server
  • Persistence of application and user authorizations (MAC Auth)

State & Persistence

This application state is hidden behind a persistence interface TentPHP\Persistence\ApplicationState. We are shipping a Doctrine DBAL based implementation.

Other clients (PHP + other languages) put the burdon of persistence on you, returning all the data that is stateful from their methods. With the ApplicationState interface you can implement this yourself, or use our Doctrine backend. In any case this simplifies the usage of the client considerably.

Install

Use Composer to install TentPHP and all its dependencies:

{
    "require": {
        "beberlei/tent-php": "*",
        "doctrine/dbal": "*"
    }
}

API (With Doctrine DBAL)

Setup & Configuration

<?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);

Request Login URL for User

$loginUrl = $client->getLoginUrl('https://beberlei.tent.is');
header("Location: " . $loginUrl);

Authorize after OAuth grant

$client->authorize($_GET['state'], $_GET['code']);

Get UserClient

$user = $client->getUserClient('https://beberlei.tent.is');

tentphp's People

Contributors

beberlei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tentphp's Issues

getting "Invalid MAC Signature" error from tent.is

Hi, I'm currently playing around with tent and php. Final goal would be a tent plugin for http://owncloud.org/ . I came across this project with helped me a lot so far. Thank you!

I try to utilize the HmacHelper.php of this project. but somehow it doesn't work for me. I checked that the code passes the signature example here https://github.com/mozilla-services/macauthlib/tree/master/macauthlib (if the algo is set to sha1).

Still i get "Invalid MAC Signature" from tent.is

heres an example:

The mac_key i got is:

76478a8ee34d962aaa6946f3bdc43b1f

and id:

s:j-o0d7dLpr_Wh_FID_UXAw

the normalized string is

1357048293
50e2e9e527aac8.55223806
DELETE
/tent/followers/LDDOUnHL5VimywfGJgAEHw
tschaul.tent.is
443

for the following request:

DELETE /tent/followers/LDDOUnHL5VimywfGJgAEHw HTTP/1.1
User-Agent: PECL::HTTP/1.7.4 (PHP/5.4.4-10)
Host: tschaul.tent.is
Authorization: MAC id="s:j-o0d7dLpr_Wh_FID_UXAw", ts="1357048293", nonce="50e2e9e527aac8.55223806", mac="cyvjRl71YQbn7hEaSbA4FnsmDOyGvgpC3Uw4bkuWeRw="
Accept: application/vnd.tent.v0+json

I get the response:

HTTP/1.1 403 Forbidden
Server: nginx
Date: Tue, 01 Jan 2013 13:51:35 GMT
Content-Type: application/vnd.tent.v0+json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 403 Forbidden
Cache-Control:
Request-ID: ba08933d-c986-496f-9968-311554f5427c
Strict-Transport-Security: max-age=31536000; includeSubDomains

21
{"error":"Invalid MAC Signature"}
0

Can you see any flaws?

Relative profile links in Link: header dont work

curl -v http://snooze.henklein.com/
* About to connect() to snooze.henklein.com port 80 (#0)
*   Trying 81.169.135.235... connected
* Connected to snooze.henklein.com (81.169.135.235) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.21.0 (i486-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6
> Host: snooze.henklein.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.1.19
< Date: Wed, 24 Oct 2012 12:08:46 GMT
< Transfer-Encoding: chunked
< Connection: keep-alive
< Link: </profile>; rel="https://tent.io/rels/profile"
< ETag: "b12f3dc2e8124c8b728c5d4f80f6bbaa"
< Cache-Control: max-age=0, private, must-revalidate
<
* Connection #0 to host snooze.henklein.com left intact
* Closing connection #0

Seperate Application and UserData

The user data can be session only, only the applications actually need to be saved across user sessions (to avoid spamming the tent server with applications).

Mapper for Post Entries

Post Type entries should be mappable to objects. From "getPosts" and "getPost", defaulting to "TentPHP\Post".

UserClient#createPost() and updatePost() should accept arrays as well as Post instances.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.