定制 diepfeiffe/laravel-steam-auth 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

diepfeiffe/laravel-steam-auth

最新稳定版本:1.0.0

Composer 安装命令:

composer require diepfeiffe/laravel-steam-auth

包简介

Steam Auth for Laravel

README 文档

README

Latest Stable Version Total Downloads License

Package allows you to implement Steam authentication in your Laravel project.

Requirements

  • Laravel 7+

Installation

Install the package

composer require ilzrv/laravel-steam-auth

Publish the config file

php artisan vendor:publish --provider="Ilzrv\LaravelSteamAuth\ServiceProvider"

Setup Steam API Key(s)

Add your Steam API key to your .env file. You can find it here.

if you want to use multiple API keys just list them separated by commas

STEAM_AUTH_API_KEYS=YourSteamApiKey1,YourSteamApiKey2

Tips

PendingRequest Settings

You can use any of the Laravel PendingRequest settings. Proxies and retries for example

public function __construct(Request $request)
{
    $pendingRequest = \Illuminate\Support\Facades\Http::withOptions([
        'proxy' => 'http://username:password@ip',
        'connect_timeout' => 10,
    ])->retry(3);

    $this->steamAuth = new SteamAuth($request, $pendingRequest);
}

Proxy Domain

If you want to make a proxy domain. Update redirect_url inside steam-auth.php to your absolute address like https://auth.test/login. You can use different domains for the local environment and for production like this:

<?php

return [
    'redirect_url' => env('APP_ENV', 'production') == 'production'
        ? 'https://auth.test/login'
        : null,
];

In the NGINX settings for proxy domain, you can specify the following:

server {
    listen 443 ssl http2;
    server_name auth.test;
    return 301 https://general.test$uri$is_args$args;
}

Example

In routes/web.php:

Route::get('login', [\App\Http\Controllers\Auth\SteamAuthController::class, 'login']);

Create a controller SteamAuthController.php:

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Support\Facades\Auth;
use Ilzrv\LaravelSteamAuth\SteamAuth;
use Ilzrv\LaravelSteamAuth\SteamData;

class SteamAuthController extends Controller
{
    /**
     * The SteamAuth instance.
     *
     * @var SteamAuth
     */
    protected $steamAuth;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * SteamAuthController constructor.
     *
     * @param SteamAuth $steamAuth
     */
    public function __construct(SteamAuth $steamAuth)
    {
        $this->steamAuth = $steamAuth;
    }

    /**
     * Get user data and login
     *
     * @return \Illuminate\Http\RedirectResponse
     */
    public function login()
    {
        if (!$this->steamAuth->validate()) {
            return $this->steamAuth->redirect();
        }

        $data = $this->steamAuth->getUserData();

        if (is_null($data)) {
            return $this->steamAuth->redirect();
        }

        Auth::login(
            $this->firstOrCreate($data),
            true
        );

        return redirect($this->redirectTo);
    }

    /**
     * Get the first user by SteamID or create new
     *
     * @param SteamData $data
     * @return User|\Illuminate\Database\Eloquent\Model
     */
    protected function firstOrCreate(SteamData $data)
    {
        return User::firstOrCreate([
            'steam_id' => $data->getSteamId(),
        ], [
            'name' => $data->getPersonaName(),
            'avatar' => $data->getAvatarFull(),
            'player_level' => $data->getPlayerLevel(),
            // ...and other what you need
        ]);
    }
}

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固