Added support for authorising oauth2 endpoints with the bearer header

This commit is contained in:
Adam Lavin 2016-01-01 21:11:28 +00:00
parent 6b026e8551
commit 3399f3e223

View file

@ -64,7 +64,7 @@ class AuthenticateOAuth
public function handle(Request $request, Closure $next, $requiredScope)
{
// Ensure this is a valid OAuth client.
$accessToken = $request->get('access_token');
$accessToken = $this->determineAccessToken($request, false);
// check that access token is valid at Poniverse.net
$accessTokenInfo = $this->poniverse->getAccessTokenInfo($accessToken);
@ -88,4 +88,20 @@ class AuthenticateOAuth
return $next($request);
}
private function determineAccessToken(Request $request, $headerOnly = true)
{
$header = $request->header('Authorization');
if ($header !== null && substr($header, 0, 7) === 'Bearer ') {
return trim(substr($header, 7));
}
if ($headerOnly) {
return null;
}
return $request->get('access_token');
}
}