PHP code example of setemares / freee-socialite

1. Go to this page and download the library: Download setemares/freee-socialite 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/ */

    

setemares / freee-socialite example snippets


use SeteMares\Freee\Provider as FreeeProvider;

    $this->bootFreeeSocialite();

    private function bootFreeeSocialite()
    {
        $socialite = $this->app->make('Laravel\Socialite\Contracts\Factory');
        $socialite->extend('freee', function ($app) use ($socialite) {
            $config = $app['config']['services.freee'];
            return $socialite->buildProvider(FreeeProvider::class, $config);
        });
    }

'freee' => [
    'client_id' => env('FREEE_CLIENT_ID', ''),
    'client_secret' => env('FREEE_CLIENT_SECRET', ''),
    'redirect' => env('FREEE_CALLBACK', 'urn:ietf:wg:oauth:2.0:oob')
]

    public function oauthRedirect()
    {
        return Socialite::driver('freee')
            ->with(['access_type' => 'offline'])
            ->redirect();
    }
    public function oauthCallback()
    {
        try {
            $user = Socialite::driver('freee')
                ->user();
        } catch (\Exception $e) {
            return $this->respondError(Lang::getFromJson("No user in oauth response"), 422);
        }
        // $user contains freee user `id` and `companies` array besides
        // token information (`token`, `expiresIn`, `refreshToken`)
    }

    try {
        $data = Socialite::driver('freee')->refreshToken($refreshToken);
    } catch (\Exception $e) {
        // GuzzleHttp\Exception\ClientException:
        return $e->getMessage());
    }