PHP code example of daisuke85a / freee-accounting-sdk
1. Go to this page and download the library: Download daisuke85a/freee-accounting-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
daisuke85a / freee-accounting-sdk example snippets
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
// ↓↓ ここから ↓↓
// use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
use App\User;
// ↑↑ ここまで編集 ↑↑
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
// ↓↓ ここから ↓↓
// use AuthenticatesUsers;
// ↑↑ ここまで編集 ↑↑
// ... 中略 ...
// ↓↓ ここから ↓↓
/**
* Redirect the user to the Freee Accounting authentication page.
*
* @return \Illuminate\Http\Response
*/
public function redirectToProvider()
{
return Socialite::driver('freeeaccounting')->redirect();
}
/**
* Obtain the user information from Freee Accounting.
*
* @return \Illuminate\Http\Response
*/
public function handleProviderCallback()
{
$user = Socialite::driver('freeeaccounting')->user();
$loggedInUser = User::updateOrCreate(
[
'freee_id' => $user->id,
],
[
'name' => $user->name,
'email' => $user->email,
'first_name' => $user->first_name,
'last_name' => $user->last_name,
'token' => $user->token,
]
);
Auth::login($loggedInUser);
return redirect($this->redirectTo);
}
public function logout()
{
Auth::logout();
return redirect()->intended('/');
}
// ↑↑ ここまで追加 ↑↑
}