added a Trait for EveAuth2
eve online service provider 2 eve online socialite provider 2
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
use Laravel\Socialite\Two\InvalidStateException;
|
||||
|
||||
trait EveAuth2 {
|
||||
protected $user;
|
||||
|
||||
public function login() {
|
||||
try {
|
||||
return Socialite::driver('eveonline')->redirect();
|
||||
} catch(Exception $e) {
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
public function callback() {
|
||||
try {
|
||||
$this->user = Socialite::driver('eveonline')->user();
|
||||
} catch(InvalidStateException $e) {
|
||||
return back();
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function get_character() {
|
||||
//Get more detailed character data from CREST
|
||||
$httpClient = new Client();
|
||||
|
||||
$url = "https://esi.evetech.net/latest/characters/{$this->user->id}/?datasource=tranquility";
|
||||
|
||||
try {
|
||||
$response = $httpClient->get($url);
|
||||
} catch (Exception $exception) {
|
||||
return abort(504, 'ESI is not reachable, try again late.');
|
||||
}
|
||||
|
||||
return json_decode($response->getBody()->getContents());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user