Skip to content

Commit c37a2ac

Browse files
authored
Merge pull request #11065 from nanaya/oauth-client-check
Use correct deny flow on oauth authorisation
2 parents c7d60e5 + d3b1510 commit c37a2ac

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

app/Exceptions/Handler.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ public static function statusCode($e)
7171
return 401;
7272
} elseif ($e instanceof AuthorizationException || $e instanceof MissingScopeException) {
7373
return 403;
74-
} elseif (static::isOAuthServerException($e)) {
75-
return $e->getPrevious()->getHttpStatusCode();
7674
} else {
7775
return 500;
7876
}
@@ -117,6 +115,10 @@ public function report(Throwable $e)
117115
*/
118116
public function render($request, Throwable $e)
119117
{
118+
if (static::isOAuthServerException($e)) {
119+
return parent::render($request, $e);
120+
}
121+
120122
if ($e instanceof HttpResponseException || $e instanceof UserProfilePageLookupException) {
121123
return $e->getResponse();
122124
}
@@ -135,7 +137,7 @@ public function render($request, Throwable $e)
135137

136138
$isJsonRequest = is_json_request();
137139

138-
if ($GLOBALS['cfg']['app']['debug'] || ($isJsonRequest && static::isOAuthServerException($e))) {
140+
if ($GLOBALS['cfg']['app']['debug']) {
139141
$response = parent::render($request, $e);
140142
} else {
141143
$message = static::exceptionMessage($e);

app/Http/Controllers/Passport/AuthorizationController.php

+7-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Illuminate\Http\Request;
99
use Laravel\Passport\ClientRepository;
10+
use Laravel\Passport\Exceptions\AuthenticationException;
1011
use Laravel\Passport\Http\Controllers\AuthorizationController as PassportAuthorizationController;
1112
use Laravel\Passport\Passport;
1213
use Laravel\Passport\TokenRepository;
@@ -35,21 +36,17 @@ public function authorize(
3536
ClientRepository $clients,
3637
TokenRepository $tokens
3738
) {
38-
$redirectUri = presence(trim(get_string($request['redirect_uri']) ?? ''));
39-
40-
abort_if($redirectUri === null, 400, osu_trans('model_validation.required', ['attribute' => 'redirect_uri']));
41-
42-
if (!auth()->check()) {
43-
// Breaks when url contains hash ("#").
44-
$separator = strpos($redirectUri, '?') === false ? '?' : '&';
45-
$cancelUrl = "{$redirectUri}{$separator}error=access_denied";
39+
try {
40+
return parent::authorize($this->normalizeRequestScopes($psrRequest), $request, $clients, $tokens);
41+
} catch (AuthenticationException $_e) {
42+
$cancelUrl = $request->fullUrl();
43+
$cancelUrl .= strpos($cancelUrl, '?') === false ? '?' : '&';
44+
$cancelUrl .= 'prompt=none';
4645

4746
return ext_view('sessions.create', [
4847
'cancelUrl' => $cancelUrl,
4948
]);
5049
}
51-
52-
return parent::authorize($this->normalizeRequestScopes($psrRequest), $request, $clients, $tokens);
5350
}
5451

5552
/**

0 commit comments

Comments
 (0)