lightair/lumen-auth-via-steam

此包已被放弃,不再维护。未建议替代包。

Lumen Steam Auth

v8.0.0 2021-08-21 19:42 UTC

This package is auto-updated.

Last update: 2024-05-17 10:51:44 UTC


README

此包是Lumen 7.0.*服务提供者,提供对Steam OpenID的支持,并且非常容易与任何需要Steam认证的项目集成。

通过Composer安装

将以下内容添加到您的composer.json文件中的require对象

"lightair/lumen-auth-via-steam": "v7.0.*"

对于v5.4,请使用v5.4.1版本的包

之后,运行composer install安装包。

在文件bootstrap/app.php中取消注释$app->withFacades()并添加

$app->register(LightAir\LumenAuthViaSteam\SteamServiceProvider::class);

最后,发布配置文件。

php artisan vendor:publish

使用示例

config/steam-auth.php

return [

    /*
     * Redirect URL after login
     */
    'redirect_url' => '/login',
    /*
     *  API Key (http://steamcommunity.com/dev/apikey)
     */
    'api_key' => 'Your API Key',
    /*
     * Is using https?
     */
    'https' => false
];

routes/web.php

$router->get('/login',  'AuthController@login');

AuthController

namespace App\Http\Controllers;

use LightAir\LumenAuthViaSteam\SteamAuth;
use App\User;
use Auth;

class AuthController extends Controller
{
    /**
     * @var SteamAuth
     */
    private $steam;

    public function __construct(SteamAuth $steam)
    {
        $this->steam = $steam;
    }

    public function login()
    {
        if ($this->steam->validate()) {
            $info = $this->steam->getUserInfo();
            if (!is_null($info)) {
                $user = User::where('steamid', $info->steamID64)->first();
                if (is_null($user)) {
                    $user = User::create([
                        'username' => $info->personaname,
                        'avatar'   => $info->avatarfull,
                        'steamid'  => $info->steamID64
                    ]);
                }
            	Auth::login($user, true);
            	return redirect('/'); // redirect to site
            }
        }
        return $this->steam->redirect(); // redirect to Steam login page
    }
}