mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2025-03-29 14:27:46 +01:00
Remove reliance on facades/helpers, and added in a typehint, in AuthenticateOAuth middleware.
This commit is contained in:
parent
991f8df661
commit
6b026e8551
1 changed files with 19 additions and 5 deletions
|
@ -20,9 +20,11 @@
|
||||||
|
|
||||||
namespace Poniverse\Ponyfm\Http\Middleware;
|
namespace Poniverse\Ponyfm\Http\Middleware;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use GuzzleHttp;
|
use GuzzleHttp;
|
||||||
|
use Illuminate\Auth\Guard;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Session\Store;
|
||||||
use Poniverse;
|
use Poniverse;
|
||||||
use Poniverse\Ponyfm\Models\User;
|
use Poniverse\Ponyfm\Models\User;
|
||||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
|
@ -34,8 +36,20 @@ class AuthenticateOAuth
|
||||||
*/
|
*/
|
||||||
private $poniverse;
|
private $poniverse;
|
||||||
|
|
||||||
public function __construct(Poniverse $poniverse) {
|
/**
|
||||||
|
* @var Guard
|
||||||
|
*/
|
||||||
|
private $auth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Store
|
||||||
|
*/
|
||||||
|
private $session;
|
||||||
|
|
||||||
|
public function __construct(Poniverse $poniverse, Guard $auth, Store $session) {
|
||||||
$this->poniverse = $poniverse;
|
$this->poniverse = $poniverse;
|
||||||
|
$this->auth = $auth;
|
||||||
|
$this->session = $session;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,7 +61,7 @@ class AuthenticateOAuth
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws \OAuth2\Exception
|
* @throws \OAuth2\Exception
|
||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next, $requiredScope)
|
public function handle(Request $request, Closure $next, $requiredScope)
|
||||||
{
|
{
|
||||||
// Ensure this is a valid OAuth client.
|
// Ensure this is a valid OAuth client.
|
||||||
$accessToken = $request->get('access_token');
|
$accessToken = $request->get('access_token');
|
||||||
|
@ -65,12 +79,12 @@ class AuthenticateOAuth
|
||||||
|
|
||||||
// Log in as the given user, creating the account if necessary.
|
// Log in as the given user, creating the account if necessary.
|
||||||
$this->poniverse->setAccessToken($accessToken);
|
$this->poniverse->setAccessToken($accessToken);
|
||||||
session()->put('api_client_id', $accessTokenInfo->getClientId());
|
$this->session->put('api_client_id', $accessTokenInfo->getClientId());
|
||||||
|
|
||||||
$poniverseUser = $this->poniverse->getUser();
|
$poniverseUser = $this->poniverse->getUser();
|
||||||
|
|
||||||
$user = User::findOrCreate($poniverseUser['username'], $poniverseUser['display_name'], $poniverseUser['email']);
|
$user = User::findOrCreate($poniverseUser['username'], $poniverseUser['display_name'], $poniverseUser['email']);
|
||||||
Auth::onceUsingId($user);
|
$this->auth->onceUsingId($user);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue