Created
August 24, 2012 22:52
-
-
Save ludofleury/3456755 to your computer and use it in GitHub Desktop.
OAuth2 bearer token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// because php sucks at providing custom headers... | |
$headers = apache_request_headers(); | |
if (isset($headers['Authorization'])) { | |
$this->headers->set('Authorization', $headers['Authorization']); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Kutio\Security\OAuth2; | |
trait Request | |
{ | |
/** | |
* An OAuth access token object | |
* | |
* @var OAuth2\AccessInterface | |
*/ | |
private $access; | |
public function isAuthorized() | |
{ | |
return true; | |
} | |
public function hasScope($scope) | |
{ | |
return $this->access->hasScope($scope); | |
} | |
public function setAccess(AccessInterface $access) | |
{ | |
$this->access = $access; | |
} | |
public function getAccess() | |
{ | |
return $this->access; | |
} | |
/** | |
* Return the OAuth token provided in the Authorization header | |
* | |
* @param string $type The OAuth2 access token type expected (Bearer, HMAC) | |
* | |
* @return string|null The OAuth2 access token or NULL | |
*/ | |
public function getOAuthToken($type = 'Bearer') | |
{ | |
$oauthToken = null; | |
$base64pattern = '(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})'; | |
if (preg_match('#^'.$type.' ('.$base64pattern.')$#', $this->headers->get('Authorization'), $matches)) { | |
$oauthToken = $matches[1]; | |
} | |
return $oauthToken; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment