Update v1.0.6

This commit is contained in:
Bhanu Slathia
2016-02-16 23:24:52 +05:30
parent c710c20b9e
commit b1f62846ab
7662 changed files with 1361647 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
<?php
namespace Tymon\JWTAuth\Claims;
class Audience extends Claim
{
/**
* The claim name
*
* @var string
*/
protected $name = 'aud';
}

View File

@@ -0,0 +1,112 @@
<?php
namespace Tymon\JWTAuth\Claims;
use Tymon\JWTAuth\Exceptions\InvalidClaimException;
abstract class Claim implements ClaimInterface
{
/**
* The claim name
*
* @var string
*/
protected $name;
/**
* The claim value
*
* @var mixed
*/
private $value;
/**
* @param mixed $value
*/
public function __construct($value)
{
$this->setValue($value);
}
/**
* Set the claim value, and call a validate method if available
*
* @param $value
* @throws \Tymon\JWTAuth\Exceptions\InvalidClaimException
* @return $this
*/
public function setValue($value)
{
if (! $this->validate($value)) {
throw new InvalidClaimException('Invalid value provided for claim "' . $this->getName() . '": ' . $value);
}
$this->value = $value;
return $this;
}
/**
* Get the claim value
*
* @return mixed
*/
public function getValue()
{
return $this->value;
}
/**
* Set the claim name
*
* @param string $name
* @return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get the claim name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Validate the Claim value
*
* @param $value
* @return boolean
*/
protected function validate($value)
{
return true;
}
/**
* Build a key value array comprising of the claim name and value
*
* @return array
*/
public function toArray()
{
return [$this->getName() => $this->getValue()];
}
/**
* Get the claim as a string
*
* @return string
*/
public function __toString()
{
return json_encode($this->toArray(), JSON_UNESCAPED_SLASHES);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Tymon\JWTAuth\Claims;
interface ClaimInterface
{
/**
* Set the claim value, and call a validate method if available
*
* @param mixed
* @return Claim
*/
public function setValue($value);
/**
* Get the claim value
*
* @return mixed
*/
public function getValue();
/**
* Set the claim name
*
* @param string $name
* @return Claim
*/
public function setName($name);
/**
* Get the claim name
*
* @return string
*/
public function getName();
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Tymon\JWTAuth\Claims;
class Custom extends Claim
{
/**
* @param string $name
* @param mixed $value
*/
public function __construct($name, $value)
{
parent::__construct($value);
$this->setName($name);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Tymon\JWTAuth\Claims;
class Expiration extends Claim
{
/**
* The claim name
*
* @var string
*/
protected $name = 'exp';
/**
* Validate the expiry claim
*
* @param mixed $value
* @return boolean
*/
protected function validate($value)
{
return is_numeric($value);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Tymon\JWTAuth\Claims;
class Factory
{
/**
* @var array
*/
private static $classMap = [
'aud' => 'Tymon\JWTAuth\Claims\Audience',
'exp' => 'Tymon\JWTAuth\Claims\Expiration',
'iat' => 'Tymon\JWTAuth\Claims\IssuedAt',
'iss' => 'Tymon\JWTAuth\Claims\Issuer',
'jti' => 'Tymon\JWTAuth\Claims\JwtId',
'nbf' => 'Tymon\JWTAuth\Claims\NotBefore',
'sub' => 'Tymon\JWTAuth\Claims\Subject'
];
/**
* Get the instance of the claim when passing the name and value
*
* @param string $name
* @param mixed $value
* @return \Tymon\JWTAuth\Claims\Claim
*/
public function get($name, $value)
{
if ($this->has($name)) {
return new self::$classMap[$name]($value);
}
return new Custom($name, $value);
}
/**
* Check whether the claim exists
*
* @param string $name
* @return boolean
*/
public function has($name)
{
return array_key_exists($name, self::$classMap);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Tymon\JWTAuth\Claims;
class IssuedAt extends Claim
{
/**
* The claim name
*
* @var string
*/
protected $name = 'iat';
/**
* Validate the issued at claim
*
* @param mixed $value
* @return boolean
*/
protected function validate($value)
{
return is_numeric($value);
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Tymon\JWTAuth\Claims;
class Issuer extends Claim
{
/**
* The claim name
*
* @var string
*/
protected $name = 'iss';
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Tymon\JWTAuth\Claims;
class JwtId extends Claim
{
/**
* The claim name
*
* @var string
*/
protected $name = 'jti';
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Tymon\JWTAuth\Claims;
class NotBefore extends Claim
{
/**
* The claim name
*
* @var string
*/
protected $name = 'nbf';
/**
* Validate the not before claim
*
* @param mixed $value
* @return boolean
*/
protected function validate($value)
{
return is_numeric($value);
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Tymon\JWTAuth\Claims;
class Subject extends Claim
{
/**
* The claim name
*
* @var string
*/
protected $name = 'sub';
}