@@ -52,12 +52,14 @@ public function __construct(TokenService $accessTokenService)
5252 * Get the access token
5353 *
5454 * Note that this method will only match tokens that are not expired and match the given scopes (if any).
55- * Otherwise, null will be returned
55+ * If no token is pass, this method will return null, but if a token is given does not exist (ie. has been
56+ * deleted) or is not valid, then it will trigger an exception
5657 *
5758 * @link http://tools.ietf.org/html/rfc6750#page-5
5859 * @param HttpRequest $request
5960 * @param array $scopes
6061 * @return AccessToken|null
62+ * @throws Exception\InvalidAccessTokenException If given access token is invalid or expired
6163 */
6264 public function getAccessToken (HttpRequest $ request , $ scopes = [])
6365 {
@@ -68,7 +70,7 @@ public function getAccessToken(HttpRequest $request, $scopes = [])
6870 $ token = $ this ->accessTokenService ->getToken ($ token );
6971
7072 if ($ token === null || !$ this ->isTokenValid ($ token , $ scopes )) {
71- return null ;
73+ throw new InvalidAccessTokenException ( ' Access token has expired or has been deleted ' ) ;
7274 }
7375
7476 return $ token ;
@@ -79,7 +81,6 @@ public function getAccessToken(HttpRequest $request, $scopes = [])
7981 *
8082 * @param HttpRequest $request
8183 * @return string|null
82- * @throws Exception\InvalidAccessTokenException If access token is malformed in the Authorization header
8384 */
8485 private function extractAccessToken (HttpRequest $ request )
8586 {
@@ -89,16 +90,16 @@ private function extractAccessToken(HttpRequest $request)
8990 if ($ headers ->has ('Authorization ' )) {
9091 // Header value is expected to be "Bearer xxx"
9192 $ parts = explode (' ' , $ headers ->get ('Authorization ' )->getFieldValue ());
92- $ token = end ($ parts ); // Access token is the last value
9393
94- if (count ($ parts ) < 2 || empty ( $ token ) ) {
95- throw new InvalidAccessTokenException ( ' No access token could be found in Authorization header ' ) ;
94+ if (count ($ parts ) < 2 ) {
95+ return null ;
9696 }
97- } else {
98- $ token = $ request -> getQuery ( ' access_token ' );
97+
98+ return end ( $ parts );
9999 }
100100
101- return $ token ;
101+ // Default back to authorization in query param
102+ return $ request ->getQuery ('access_token ' );
102103 }
103104
104105 /**
0 commit comments