Giter Club home page Giter Club 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

Watchers

 avatar

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.