I am having an issue doing something that should be easy - logging in using Google through Laravel Socialite. I'm posting all my information below in the hopes that someone can help me solve my problem.
First, in my services.php
I have the following:
'google' => [
'client_id' => 'exampleClient',
'client_secret' => 'examplesecret',
'redirect' => 'http://ift.tt/1QURgIS',
],
My routes.php
:
use Illuminate\Http\Request;
Route::get('/', function () {
return view('welcome');
});
//Social Login
Route::get('/gmaillogin',[
'uses' => 'punscontroller@getSocialAuth',
'as' => 'puns.getSocialAuth'
]);
Route::get('/your_profile',[
'uses' => 'punscontroller@getSocialAuthCallback',
'as' => 'puns.getSocialAuthCallback'
]);
Route::get('/your_awesome_profile',[
'uses' => 'punscontroller@checkifauth',
'as' => 'puns.checkifauth'
]);
My controller:
<?php namespace App\Http\Controllers;
use App\User;
use Auth;
use Laravel\Socialite\Contracts\Factory as Socialite;
class punscontroller extends Controller
{
public function __construct(Socialite $socialite){
$this->socialite = $socialite;
}
public function getSocialAuth($provider="google")
{
//if(!config("services.$provider")) abort('404'); //just to handle providers that doesn't exist
return $this->socialite->with($provider)->redirect();
}
public function getSocialAuthCallback($provider="google")
{
if($buser = $this->socialite->with($provider)->user()){
$gmail_id = $buser->getId();
$name = $buser->getName;
$email = $buser->getEmail();
$user = User::where('gmail_id', $gmail_id)->first();
// register (if no user)
if (!$user) {
$user = new User;
$user->gmail_id = $gmail_id;
$user->name = $name;
$user->email = $email;
$user->save();
}
// login
Auth::loginUsingId($user->id);
return redirect('your_awesome_profile');
}else{
return 'something went wrong';
}
}
public function checkifauth()
{
if(Auth::check())
{
return view('your_profile');
}
else{
echo "Insufficient Privileges! Please visit the homepage and login!";
}
}
}
I get an error on http://ift.tt/1VRUsTC...
that says Access Not Configured but my keys are correct and there doesn't appear to be anything missing on the Google console side. Any ideas what I am doing wrong?
As I understand it, the first step I satisfy when I hit a button to take me to http://ift.tt/1QUReAL
, and then enter my google id. Then I am hit with the redirect to your_profile...
and the error.
Please help!
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1QUReAJ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire