Thank about this question and answers, but I cant get it work. I have install php make:auth. Then I add this: https://docs.microsoft.com/en-us/graph/tutorials/php?tutorial-step=3
Next step i read this article and add this code:
$user = $graph->createRequest('GET', '/me')
->setReturnType(Model\User::class)
->execute();
// HERE YOU CAN SAVE THE USER IN THE DB + LOGIN WITH LARAVEL
//https://stackoverflow.com/questions/38268137/laravel-5-2-split-string-first-name-last-name
$split = explode(" ", $user->getDisplayName());
$firstname = array_shift($split);
$lastname = implode(" ", $split);
$user = User::firstOrCreate([
'email' => $user->getmail()
], [
'surname' => $lastname,
'name' => $firstname,
'password' => 'secret'
]);
auth()->login($user);
// dd($user);
But now all the time I get this error: Call to undefined method App\User::getDisplayName(). I add this
use App\User;
In AuthController, but it didnt work.
Can you help please with this error. I understand that if user is created then he redircet to home view?
I was planing this use with default laravel autenfication (make:auth).
p.s.
This looks like my route (web.php) file:
Route::get('/', function () {
return view('welcome');
});
Route::get('/signin', 'AuthController@signin');
Route::get('/callback', 'AuthController@callback');
Route::get('/signout', 'AuthController@signout');
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Add these erros I get:
(1/1) BadMethodCallException
Call to undefined method App\User::getDisplayName()
in ForwardsCalls.php line 50
at Model::throwBadMethodCallException('getDisplayName')
in ForwardsCalls.php line 36
at Model->forwardCallTo(object(Builder), 'getDisplayName', array())
in Model.php line 1618
at Model->__call('getDisplayName', array())
in TokenCache.php line 12
at TokenCache->storeTokens(object(AccessToken), object(User))
in AuthController.php line 106
at AuthController->callback(object(Request))
at call_user_func_array(array(object(AuthController), 'callback'), array(object(Request)))
in Controller.php line 54
at Controller->callAction('callback', array(object(Request)))
in ControllerDispatcher.php line 45
at ControllerDispatcher->dispatch(object(Route), object(AuthController), 'callback')
in Route.php line 219
at Route->runController()
in Route.php line 176
at Route->run()
in Router.php line 680