GithubHelp home page GithubHelp logo

ilzrv / laravel-steam-auth Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 4.0 56 KB

Steam Auth for Laravel

License: MIT License

PHP 100.00%
steam steam-auth laravel-steam-auth steam-authentication laravel laravel-steam steam-api

laravel-steam-auth's Introduction

Steam Auth for Laravel

Latest Stable Version Total Downloads GitHub Workflow Status Codecov License

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

Requirements

  • Laravel 9+
  • PHP 8.1+

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

Client Settings

You can use any settings that your client supports, for example, a Guzzle Proxy:

<?php

declare(strict_types=1);

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use Illuminate\Http\Request;
use Ilzrv\LaravelSteamAuth\SteamAuthenticator;

public function __invoke(
    Request $request,
    HttpFactory $httpFactory,
): RedirectResponse {
    $client = new Client([
        'proxy' => 'socks5://user:[email protected]:1080',
    ]);

    $steamAuthenticator = new SteamAuthenticator(
        new Uri($request->getUri()),
        $client,
        $httpFactory,
    );
    
    // Continuation of your code...
}

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

declare(strict_types=1);

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;
}

Basic example

In routes/web.php:

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

Create a controller SteamAuthController.php:

<?php

declare(strict_types=1);

namespace App\Http\Controllers\Auth;

use App\Models\User;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use GuzzleHttp\Psr7\Uri;
use Illuminate\Auth\AuthManager;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Ilzrv\LaravelSteamAuth\Exceptions\Authentication\SteamResponseNotValidAuthenticationException;
use Ilzrv\LaravelSteamAuth\Exceptions\Validation\ValidationException;
use Ilzrv\LaravelSteamAuth\SteamAuthenticator;
use Ilzrv\LaravelSteamAuth\SteamUserDto;

final class SteamAuthController
{
    public function __invoke(
        Request $request,
        Redirector $redirector,
        Client $client,
        HttpFactory $httpFactory,
        AuthManager $authManager,
    ): RedirectResponse {
        $steamAuthenticator = new SteamAuthenticator(
            new Uri($request->getUri()),
            $client,
            $httpFactory,
        );

        try {
            $steamAuthenticator->auth();
        } catch (ValidationException|SteamResponseNotValidAuthenticationException) {
            return $redirector->to(
                $steamAuthenticator->buildAuthUrl()
            );
        }

        $steamUser = $steamAuthenticator->getSteamUser();

        $authManager->login(
            $this->firstOrCreate($steamUser),
            true
        );

        return $redirector->to('/');
    }

    private function firstOrCreate(SteamUserDto $steamUser): User
    {
        return User::firstOrCreate([
            'steam_id' => $steamUser->getSteamId(),
        ], [
            'name' => $steamUser->getPersonaName(),
            'avatar' => $steamUser->getAvatarFull(),
            'player_level' => $steamUser->getPlayerLevel(),
            // ...and other what you need
        ]);
    }
}

laravel-steam-auth's People

Contributors

ilzrv avatar xshaan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-steam-auth's Issues

Not working at all... ofc

I don't know what you think you are doing here, but this will never work. You are making a view which should handle the response of steam with the data? That is not how things work. You create a view which returns. And you set the redirect URL to your handle function which handles the data provided by steam. Highly not recommend using this since it will simply not work at all. This was just 1 example of tons which are not working.

You should instead use this https://github.com/invisnik/laravel-steam-auth which does work, also on laravel 8 and which does handle the responses like it should be done

Error with laravel steam auth

Hello i would like use your script , i have test but it doesnt work, can you help me? you can contact me on discord : eliouce

Route [login] not defined.

Добрый день, получаю такую ошибку. Делаю всё по инструкции. Laravel 8.

Route [login] not defined.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.