在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):invisnik/laravel-steam-auth开源软件地址(OpenSource Url):https://github.com/invisnik/laravel-steam-auth开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Steam authentication for LaravelThis package is a Laravel 5 service provider which provides support for Steam OpenID and is very easy to integrate with any project that requires Steam authentication. Requirements
InstallationVia Composercomposer require invisnik/laravel-steam-auth Steam API KeyAdd your Steam API key to your
Config FilesPublish the config file.
Usage exampleIn return [
/*
* Redirect URL after login
*/
'redirect_url' => '/auth/steam/handle',
/*
* Realm override. Bypass domain ban by Valve.
* Use alternative domain with redirection to main for authentication (banned by valve).
*/
// 'realm' => 'redirected.com',
/*
* API Key (set in .env file) [http://steamcommunity.com/dev/apikey]
*/
'api_key' => env('STEAM_API_KEY', ''),
/*
* Is using https?
*/
'https' => false,
]; In Route::get('auth/steam', 'AuthController@redirectToSteam')->name('auth.steam');
Route::get('auth/steam/handle', 'AuthController@handle')->name('auth.steam.handle'); Note: if you want to keep using Laravel's default logout route, add the following as well: Route::post('logout', 'Auth\LoginController@logout')->name('logout'); In namespace App\Http\Controllers;
use Invisnik\LaravelSteamAuth\SteamAuth;
use App\User;
use Auth;
class AuthController extends Controller
{
/**
* The SteamAuth instance.
*
* @var SteamAuth
*/
protected $steam;
/**
* The redirect URL.
*
* @var string
*/
protected $redirectURL = '/';
/**
* AuthController constructor.
*
* @param SteamAuth $steam
*/
public function __construct(SteamAuth $steam)
{
$this->steam = $steam;
}
/**
* Redirect the user to the authentication page
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function redirectToSteam()
{
return $this->steam->redirect();
}
/**
* Get user info and log in
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function handle()
{
if ($this->steam->validate()) {
$info = $this->steam->getUserInfo();
if (!is_null($info)) {
$user = $this->findOrNewUser($info);
Auth::login($user, true);
return redirect($this->redirectURL); // redirect to site
}
}
return $this->redirectToSteam();
}
/**
* Getting user by info or created if not exists
*
* @param $info
* @return User
*/
protected function findOrNewUser($info)
{
$user = User::where('steamid', $info->steamID64)->first();
if (!is_null($user)) {
return $user;
}
return User::create([
'username' => $info->personaname,
'avatar' => $info->avatarfull,
'steamid' => $info->steamID64
]);
}
} Should you wish to use a login redirection URL that is differant from the one you specified in the config // Inside your controller login method
$this->steam->setRedirectUrl(route('login.route'));
...
return $this->steam->redirect(); If you need another steamID you can use another package to convert the given steamID64 to another type like xPaw/SteamID. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论