Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Improve authenticateViaBearerToken() performance #1447

Merged
merged 1 commit into from
May 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions src/Guards/TokenGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,6 @@ public function __construct(
$this->encrypter = $encrypter;
}

/**
* Determine if the requested provider matches the client's provider.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function hasValidProvider(Request $request)
{
$client = $this->client($request);

if ($client && ! $client->provider) {
return true;
}

return $client && $client->provider === $this->provider->getProviderName();
}

/**
* Get the user for the incoming request.
*
Expand Down Expand Up @@ -148,7 +131,17 @@ protected function authenticateViaBearerToken($request)
return;
}

if (! $this->hasValidProvider($request)) {
$client = $this->clients->findActive(
$psr->getAttribute('oauth_client_id')
);

// Verify if the client that issued this token exists and is still valid
if (! $client) {
return;
}

// Verify if the client that issued this token matches the requested provider.
if ($client->provider && $client->provider !== $this->provider->getProviderName()) {
return;
}

Expand All @@ -170,15 +163,6 @@ protected function authenticateViaBearerToken($request)
$psr->getAttribute('oauth_access_token_id')
);

$clientId = $psr->getAttribute('oauth_client_id');

// Finally, we will verify if the client that issued this token is still valid and
// its tokens may still be used. If not, we will bail out since we don't want a
// user to be able to send access tokens for deleted or revoked applications.
if ($this->clients->revoked($clientId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check still happening somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->clients->findActive() above makes sure the $client is not revoked.

return;
}

return $token ? $user->withAccessToken($token) : null;
}

Expand Down