ivao-brasil / ivao-socialite
A Laravel Socialite Provider for IVAO
Requires
- php: ^7.3|^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.0
- laravel/socialite: ^5.0
Requires (Dev)
- phpunit/phpunit: ^9.3
This package is auto-updated.
Last update: 2023-06-11 18:37:23 UTC
README
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.