Skip to content

Commit

Permalink
Auth progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Hughes committed Mar 4, 2015
1 parent 1c99e12 commit 850bbff
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/HumanApi/Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Choccybiccy\HumanApi;

use SebastianBergmann\Exporter\Exception;

/**
* Class Auth
* @package Choccybiccy\HumanApi
*/
class Auth extends Api
{

/**
* @var string
*/
protected $apiUrl = "https://user.humanapi.co";

/**
* @var int
*/
protected $apiVersion = 1;

/**
* @var stdClass
*/
protected $sessionTokenObject;

/**
* Constructor
*
* @see https://docs.humanapi.co/docs/connect-backend
*
* @param string $sessionTokenObject
* @param string $clientSecret
*/
public function __construct($sessionTokenObject, $clientSecret)
{

$sessionTokenObject = $this->decodeJson($sessionTokenObject);
$sessionTokenObject->clientSecret = $clientSecret;
$this->sessionTokenObject = $sessionTokenObject;

parent::__construct();

}

/**
* Finish the auth flow and post to connect endpoint
*/
public function finish()
{
$response = $this->post(
$this->buildUrlParts(array("tokens"), "connect"),
array(
"json" => (array) $this->sessionTokenObject,
)
);
}

/**
* Decode JSON data
*
* @param string $str JSON data
* @return stdClass
*/
protected function decodeJson($str)
{
$str = preg_replace("/([a-zA-Z0-9_]+?):/" , "\"$1\":", $str); // fix variable names
return json_decode($str);
}
}

0 comments on commit 850bbff

Please sign in to comment.