@@ -32,20 +32,20 @@ public function setClient(\GuzzleHttp\Client $client) {
3232 /**
3333 */
3434 protected function getIntrospect ($ accessToken ) {
35- $ guzzle = $ this ->getClient ();
35+ $ guzzle = $ this ->getClient ();
3636
3737 $ response = $ guzzle ->post ( config ( 'authorizationserver.authorization_server_introspect_url ' ), [
3838 'form_params ' => [
3939 'token_type_hint ' => 'access_token ' ,
4040
4141 // This is the access token for verifying the user's access token
42- 'token ' => $ this -> getAccessToken ()
42+ 'token ' => $ accessToken
4343 ],
4444 'headers ' => [
45- 'Authorization ' => 'Bearer ' . $ accessToken
45+ 'Authorization ' => 'Bearer ' . $ this -> getAccessToken ()
4646 ]
4747 ] );
48-
48+
4949 return json_decode ( ( string ) $ response ->getBody (), true );
5050 }
5151
@@ -88,9 +88,9 @@ protected function getAccessToken() {
8888 * @param \Closure $next
8989 * @return mixed
9090 */
91- public function handle ($ request , Closure $ next , $ scopes = null ) {
91+ public function handle ($ request , Closure $ next , ... $ scopes ) {
9292 $ authorization = $ request ->header ( 'Authorization ' );
93-
93+
9494 if (strlen ( $ authorization ) == 0 ) {
9595 throw new InvalidInputException ( "No Authorization header present " );
9696 }
@@ -105,7 +105,6 @@ public function handle($request, Closure $next, $scopes = null) {
105105 try {
106106
107107 $ result = $ this ->getIntrospect ( $ receivedAccessToken );
108-
109108 if (! $ result ['active ' ]) {
110109
111110 throw new InvalidAccessTokenException ( "Invalid token! " );
@@ -119,15 +118,17 @@ public function handle($request, Closure $next, $scopes = null) {
119118
120119 $ scopesForToken = \explode ( " " , $ result ['scope ' ] );
121120
122- if (count ( $ scopes ) != count ( array_intersect ( $ scopes , $ scopesForToken ) )) {
123- throw new InvalidAccessTokenException ( "Missing required scopes! " );
121+ if ( count ( $ misingScopes = array_diff ( $ scopes , $ scopesForToken ) ) > 0 ) {
122+ throw new InvalidAccessTokenException ( "Missing the following required scopes: " . implode ( " , " , $ misingScopes ) );
124123 } else {
125124 }
126125 }
127126 } catch ( RequestException $ e ) {
128127 if ($ e ->hasResponse ()) {
129128 $ result = json_decode ( ( string ) $ e ->getResponse ()->getBody (), true );
130129
130+ var_dump ($ result );exit ;
131+
131132 if (isset ( $ result ['error ' ] )) {
132133 throw new InvalidAccessTokenException ( $ result ['error ' ] ['title ' ] ?? "Invalid token! " );
133134 } else {
0 commit comments