Initial integration with Quicken (Intuit API), rework oauth tables, update/test google login
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -10,9 +11,7 @@ use Laravel\Socialite\Facades\Socialite;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\SocialLink;
|
||||
use App\Models\Oauth;
|
||||
use App\Models\AccountOauth;
|
||||
use App\Models\User;
|
||||
use App\Models\{ProviderOauth,ProviderToken,User,UserOauth};
|
||||
use App\Providers\RouteServiceProvider;
|
||||
|
||||
class SocialLoginController extends Controller
|
||||
@@ -26,10 +25,13 @@ class SocialLoginController extends Controller
|
||||
{
|
||||
$openiduser = Socialite::with($provider)->user();
|
||||
|
||||
$oo = Oauth::firstOrCreate(['name'=>$provider,'active'=>TRUE]);
|
||||
if (! $openiduser)
|
||||
return redirect('/home')->with('error','No user details obtained.');
|
||||
|
||||
$oo = ProviderOauth::firstOrCreate(['name'=>$provider,'active'=>TRUE]);
|
||||
|
||||
// See if this user has connected and linked previously
|
||||
$aoo = $oo->accounts->where('userid',$openiduser->id);
|
||||
$aoo = $oo->users->where('userid',$openiduser->id);
|
||||
|
||||
if ($aoo->count() == 1) {
|
||||
$aoo = $aoo->first();
|
||||
@@ -59,10 +61,10 @@ class SocialLoginController extends Controller
|
||||
|
||||
// See if their is an account with this email address
|
||||
if ($uo->count() == 1) {
|
||||
$aoo = new AccountOauth;
|
||||
$aoo = new UserOauth;
|
||||
$aoo->userid = $openiduser->id;
|
||||
$aoo->oauth_data = $openiduser->user;
|
||||
$oo->accounts()->save($aoo);
|
||||
$oo->users()->save($aoo);
|
||||
|
||||
return $this->link($provider,$aoo,$uo->first());
|
||||
|
||||
@@ -78,16 +80,43 @@ class SocialLoginController extends Controller
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
public function handleBearerTokenCallback($provider)
|
||||
{
|
||||
$openiduser = Socialite::with($provider)->user();
|
||||
|
||||
if (! $openiduser)
|
||||
return redirect('/home')->with('error','No user details obtained.');
|
||||
|
||||
$po = ProviderOauth::where('name',$provider)->singleOrFail();
|
||||
|
||||
$uoo = ProviderToken::where('user_id',Auth::id())->where('provider_oauth_id',$po->id)->firstOrNew();
|
||||
|
||||
$uoo->user_id = Auth::id();
|
||||
$uoo->access_token = $openiduser->token;
|
||||
$uoo->access_token_expires_at = Carbon::now()->addSeconds($openiduser->expiresIn);
|
||||
$uoo->refresh_token = $openiduser->refreshToken;
|
||||
$uoo->refresh_token_expires_at = Carbon::now()->addSeconds($openiduser->refresh_token_expires_in);
|
||||
$uoo->realm_id = $openiduser->realmid;
|
||||
|
||||
$po->tokens()->save($uoo);
|
||||
|
||||
return redirect()
|
||||
->intended(RouteServiceProvider::HOME)
|
||||
->with('success','Token refreshed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* We have identified the user and oauth, just need them to confirm the link
|
||||
*
|
||||
* @param $provider
|
||||
* @param $provider
|
||||
* @param UserOauth $ao
|
||||
* @param User $uo
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function link($provider,AccountOauth $ao,User $uo)
|
||||
public function link($provider,UserOauth $ao,User $uo): \Illuminate\View\View
|
||||
{
|
||||
Mail::to($uo->email)->send(new SocialLink($ao));
|
||||
// @note If this is sent now (send()), it results in the caller to be executed a second time (handleProviderCallback()).
|
||||
Mail::to($uo->email)->queue(new SocialLink($ao));
|
||||
|
||||
return view('auth.social_link')
|
||||
->with('oauthid',$ao->id)
|
||||
@@ -97,7 +126,7 @@ class SocialLoginController extends Controller
|
||||
public function linkcomplete(Request $request,$provider)
|
||||
{
|
||||
// Load our oauth id
|
||||
$aoo = AccountOauth::findOrFail($request->post('oauthid'));
|
||||
$aoo = UserOauth::findOrFail($request->post('oauthid'));
|
||||
|
||||
// Check our email matches
|
||||
if (Arr::get($aoo->oauth_data,'email','invalid') !== $request->post('email'))
|
||||
|
Reference in New Issue
Block a user