|
|
|
|
@ -5,7 +5,8 @@ namespace App\Http\Controllers\OAuth;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Laravel\Passport\Http\Controllers\ApproveAuthorizationController;
|
|
|
|
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
|
|
|
|
use Nyholm\Psr7\Response as Psr7Response;
|
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
|
|
class OobAuthorizationController extends ApproveAuthorizationController
|
|
|
|
|
{
|
|
|
|
|
@ -14,15 +15,13 @@ class OobAuthorizationController extends ApproveAuthorizationController
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function approve(Request $request)
|
|
|
|
|
public function approve(Request $request, ResponseInterface $psrResponse): Response
|
|
|
|
|
{
|
|
|
|
|
$this->assertValidAuthToken($request);
|
|
|
|
|
|
|
|
|
|
$authRequest = $this->getAuthRequestFromSession($request);
|
|
|
|
|
$authRequest->setAuthorizationApproved(true);
|
|
|
|
|
|
|
|
|
|
return $this->withErrorHandling(function () use ($authRequest) {
|
|
|
|
|
$response = $this->server->completeAuthorizationRequest($authRequest, new Psr7Response);
|
|
|
|
|
return $this->withErrorHandling(function () use ($authRequest, $psrResponse) {
|
|
|
|
|
$response = $this->server->completeAuthorizationRequest($authRequest, $psrResponse);
|
|
|
|
|
|
|
|
|
|
if ($this->isOutOfBandRequest($authRequest)) {
|
|
|
|
|
$code = $this->extractAuthorizationCode($response);
|
|
|
|
|
@ -34,7 +33,7 @@ class OobAuthorizationController extends ApproveAuthorizationController
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->convertResponse($response);
|
|
|
|
|
});
|
|
|
|
|
}, $authRequest->getGrantTypeId() === 'implicit');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -72,29 +71,4 @@ class OobAuthorizationController extends ApproveAuthorizationController
|
|
|
|
|
|
|
|
|
|
return $params['code'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle OAuth errors for both redirect and OOB flows.
|
|
|
|
|
*
|
|
|
|
|
* @param \Closure $callback
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
protected function withErrorHandling($callback)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $callback();
|
|
|
|
|
} catch (OAuthServerException $e) {
|
|
|
|
|
if ($this->isOutOfBandRequest($this->getAuthRequestFromSession(request()))) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'error' => $e->getErrorType(),
|
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
|
'hint' => $e->getHint(),
|
|
|
|
|
], $e->getHttpStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->convertResponse(
|
|
|
|
|
$e->generateHttpResponse(new Psr7Response)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|