ivao-brasil/ivao-socialite

This package is abandoned and no longer maintained. No replacement package was suggested.

A Laravel Socialite Provider for IVAO

v1.3.0 2021-02-11 13:06 UTC

README

GitHub release (latest by date) Test GitHub Quality Gate Status Packagist Version

A Laravel Socialite Provider for IVAO.

Getting Started

In order to use this package in your Laravel projects, you must first install it. The recommended way to install this package is through Composer.

composer require ivao-brasil/ivao-socialite

After that, you must add the configuration in your Laravel config file, such as any other Socialite Provider. In order to do it, head over to your config/services.php file and add the following session:

"ivao" => [
    "redirect" => "/your-callback"
]

This callback will be the URL which will be forwarded by IVAO Login API. You can use either an URL or a route path in configuration.

Or, for development purposes, if you need to mock the IVAO login to a local application, you can override the urls called as follows:

"ivao" => [
    "redirect" => "/your-callback",
    "ivao-dev-login-url" => "https://localhost/fakeivaologin/",
    "ivao-dev-login-api" => "http://localhost/fakeivaologin/api/",
]

After that, you're good to go. You can use it in your code as any other Socialite Provider.

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;

class IvaoLoginController
{
    public function redirect()
    {
        return Socialite::driver('ivao')->redirect();
    }

    public function callback()
    {
        $ivaoUser = Socialite::driver('ivao')->user()->getRaw();

        Auth::login(new User($ivaoUser));

        return redirect()->to('home');
    }
}

Note that due to restrictions on IVAO API, Socialite user instance is heavily limited: only getId and getName methods are implemented. We recommend you use the getRaw() method, which will return you an associative array with the parsed Login API data. When you call it, you will get something like:

[
  "vid" => 385415,
  "firstName" => "Joao Pedro",
  "lastName" => "Henrique",
  "administrativeRating" => 2,
  "atcRating" => 5,
  "pilotRating" => 5,
  "division" => "BR",
  "country" => "BR",
  "staff" => [ "BR-AWM", "WD9" ]
]

In case no User Data can be extracted from the API with the provided token, the Socialite user method will return null.

Issues and contributions

If you found an error/bug/bad behavior, feel free to open an issue reporting it. Also, pull requests are welcome and pretty much appreciated.

License

This project is MIT Licensed.