Skip to content

Instantly share code, notes, and snippets.

@alexbilbie
Last active March 8, 2016 21:02
Show Gist options
  • Save alexbilbie/833024da674ecc7e5e61 to your computer and use it in GitHub Desktop.
Save alexbilbie/833024da674ecc7e5e61 to your computer and use it in GitHub Desktop.
<?php
namespace OAuth;
class AccessToken
{
/**
* @var string
*/
protected $type = 'Bearer';
/**
* @var string
*/
private $value;
/**
* @var \DateTime
*/
private $expiresAt;
/**
* @var int|string
*/
private $ownerId;
/**
* @var string
*/
private $ownerType;
/**
* @param string $value The access token value
* @param \DateTime $expiresAt The expiry time of the access token
* @param string|int $ownerId The identifier of the owner of the token
* @param string $ownerType The type of the owner (default: "user")
*/
public function __construct($value, \DateTime $expiresAt, $ownerId, $ownerType = 'user')
{
$this->value = $value;
$this->expiresAt = $expiresAt;
$this->ownerId = $ownerId;
$this->ownerType = $ownerType;
}
/**
* @return string
*/
public function __toString()
{
return $this->value;
}
/**
* @return \DateTime
*/
public function getExpiresAt()
{
return $this->expiresAt;
}
/**
* @return int|string
*/
public function getOwnerId()
{
return $this->ownerId;
}
/**
* @return string
*/
public function getOwnerType()
{
return $this->ownerType;
}
/**
* @return string
*/
public function getTokenType()
{
return $this->type;
}
}
<?php
namespace OAuth;
class MacToken extends AccessToken
{
/**
* @var string
*/
protected $type = 'MAC';
/**
* @var string
*/
private $macKey;
/**
* @var string
*/
private $macAlgorithm;
/**
* @param string $value The access token value
* @param string $macKey The MAC key value
* @param string $macAlgorithm The MAC algorithm
* @param \DateTime $expiresAt The expiry time of the access token
* @param string|int $ownerId The identifier of the owner of the token
* @param string $ownerType The type of the owner (default: "user")
*/
public function __construct($value, $macKey, $macAlgorithm, \DateTime $expiresAt, $ownerId, $ownerType = 'user')
{
parent::__construct($value, $expiresAt, $ownerId, $ownerType);
$this->macKey = $macKey;
$this->macAlgorithm = $macAlgorithm;
}
/**
* @return string
*/
public function getMacKey()
{
return $this->macKey;
}
/**
* @return string
*/
public function getMacAlgorithm()
{
return $this->macAlgorithm;
}
}
@alexbilbie
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment