Coder Social home page Coder Social logo

kanalumaddela / laravel-steam-login Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 10.0 372 KB

Steam Login for Laravel/Lumen 5.5+ / 6.x+ / 7.x+ / 8.x+

License: MIT License

PHP 100.00%
laravel steam laravel-steam php steam-api steam-authentication lumen login auth hacktoberfest steam-login packagist

laravel-steam-login's Introduction

Steam Login/Auth for Laravel/Lumen 5.5+ / 6.x+ / 7.x+ / 8.x+

Maintainability Packagist Packagist version PHP from Packagist GitHub stars GitHub forks GitHub issues GitHub license

Make sure you have made/performed the appropriate migrations. I suggest doing whatever works best for you, but certain suggestions should be followed to avoid trouble.

Version PHP Version Laravel/Lumen Version Docs
1.x 7.0+ 5.5+ Docs
2.x 7.1+ 5.6+ Docs
3.x 7.2+ 6.0+ / 7.0+ / 8.0+ Docs (I/P)

Features

  • Laravel/Lumen supported
  • Optionally redirect users to the previous page before logging in
  • Included abstract controller and routes for easy setup
  • SteamUserclass to easily retrieve a player's data

[3.x / 2.x] Quick Setup

  1. Install library
composer require kanalumaddela/laravel-steam-login
  1. Publish files
php artisan vendor:publish --force --provider kanalumaddela\LaravelSteamLogin\SteamLoginServiceProvider
  1. Create Controller
php artisan make:controller Auth\SteamLoginController
  1. Add routes routes/web.php
use App\Http\Controllers\Auth\SteamLoginController;
use kanalumaddela\LaravelSteamLogin\Facades\SteamLogin;

//...

// If using steam login only, add ['include_login_route' => true]
// to also add a /login route,

SteamLogin::routes([
    'controller' => SteamLoginController::class,
]);
  1. Edit Controller App\Http\Controllers\Auth\SteamLoginController.php
<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use kanalumaddela\LaravelSteamLogin\Http\Controllers\AbstractSteamLoginController;
use kanalumaddela\LaravelSteamLogin\SteamUser;

class SteamLoginController extends AbstractSteamLoginController
{
    /**
     * {@inheritdoc}
     */
    public function authenticated(Request $request, SteamUser $steamUser)
    {
        // auth logic goes here, below assumes User model with `steam_account_id` attribute 
        // $user = User::where('steam_account_id', $steamUser->accountId)->first();
        // \Illuminate\Support\Facades\Auth::login($user);
    }
}

Credits

Thanks to these libs which led me to make this

laravel-steam-login's People

Contributors

craighulme avatar dependabot[bot] avatar expdev07 avatar j0sh0nat0r avatar kanalumaddela avatar robertdrakedennis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-steam-login's Issues

Issue with Laravel 7 & Laragon

Hello,
I'm trying to install this, but I'm getting an error when trying to.
image

I've ext-gmp enabled in my PHP, so I'm not so sure why this happens..

Route [] not defined.

I'm probably missing something basic... but anyway...
I've also done php artisan cache:clear as issue #46 had and it has not changed my error.

Laravel 5.8
PHP 7.3

As per readme.md, required package, did force vendor publish, added routes w/ uses, created controller and pasted the controller on this page (https://github.com/kanalumaddela/laravel-steam-login/wiki/2.x-Usage-Laravel) into my controller

Navigate to /login/steam and I get the error.
InvalidArgumentException Route [] not defined.

Stack trace:

57
InvalidArgumentException 
…/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php388
56
Illuminate\Routing\UrlGenerator route
…/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php782
55
 route
…/vendor/kanalumaddela/laravel-steam-login/src/SteamLogin.php204
54
kanalumaddela\LaravelSteamLogin\SteamLogin buildLoginUrl
…/vendor/kanalumaddela/laravel-steam-login/src/SteamLogin.php427
53
kanalumaddela\LaravelSteamLogin\SteamLogin getLoginUrl
…/vendor/kanalumaddela/laravel-steam-login/src/SteamLogin.php405
52
kanalumaddela\LaravelSteamLogin\SteamLogin redirectToSteam
…/vendor/kanalumaddela/laravel-steam-login/src/Http/Controllers/AbstractSteamLoginController.php65
51
kanalumaddela\LaravelSteamLogin\Http\Controllers\AbstractSteamLoginController redirectToSteam
…/vendor/kanalumaddela/laravel-steam-login/src/Http/Controllers/AbstractSteamLoginController.php57
50
kanalumaddela\LaravelSteamLogin\Http\Controllers\AbstractSteamLoginController login
…/vendor/laravel/framework/src/Illuminate/Routing/Controller.php54

My controller if interested (the diedump/DD is because I don't want it to save a user just yet, I want it to hit the auth section so I can see it's working)

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use kanalumaddela\LaravelSteamLogin\Http\Controllers\AbstractSteamLoginController;
use kanalumaddela\LaravelSteamLogin\SteamUser;
use App\User;

class SteamLoginController extends AbstractSteamLoginController
{
    /**
     * {@inheritdoc}
     */
    public function authenticated(Request $request, SteamUser $steamUser)
    {
        dd('welcome '.$steamUser->name);
        // find user by their steam account id, example assumes `steam_account_id` on `users` table
        $user = User::where('steam_account_id', $steamUser->accountId)->first();

        // if the user doesn't exist, create them
        if (!$user) {
            $steamUser->getUserInfo(); // retrieve and set user info pulled from steam

            $user = User::create([
                'name' => $steamUser->name, // personaname
                'steam_account_id' => $steamUser->accountId,
            ]);
        }

        // login the user using the Auth facade
        Auth::login($user);

        // let the extended controller handle redirect back to the page the user was just on
    }
}

Unable to login over XML

I just tried to login using this API, which was working fine a about a week ago. I noticed there was an update and tried to update locally. Then I got an error saying:

Trying to get property of non-object

public function userInfo()
{
    switch (Config::get('steam-login.method')) {
        case 'xml':
            $data = simplexml_load_string(self::curl(sprintf(str_replace('https://', 'http://', self::STEAM_PROFILE).'/?xml=1', $this->player->steamid)), 'SimpleXMLElement', LIBXML_NOCDATA);
            $this->player->name = (string) $data->steamID;
            $this->player->realName = (string) $data->realname;
            $this->player->playerState = ucfirst((string) $data->onlineState);
            $this->player->stateMessage = (string) $data->stateMessage;
            $this->player->privacyState = ucfirst((string) $data->privacyState);
            $this->player->visibilityState = (int) $data->visibilityState;
            $this->player->avatarSmall = (string) $data->avatarIcon;
            $this->player->avatarMedium = (string) $data->avatarMedium;
            $this->player->avatarLarge = (string) $data->avatarFull;
            $this->player->profileURL = !empty((string) $data->customURL) ? sprintf(self::STEAM_PROFILE_ID, (string) $data->customURL) : sprintf(self::STEAM_PROFILE, $this->player->steamid);
            $this->player->joined = !empty($data->joined) ? $data->joined : null;
            break;
        case 'api':
            if (empty(Config::get('steam-login.api_key'))) {
                throw new RuntimeException('Steam API key not specified, please add it to your .env');
            }
            $data = json_decode(self::curl(sprintf(self::STEAM_API, Config::get('steam-login.api_key'), $this->player->steamid)));
            $data = $data->response->players[0];
            switch ($data->personastate) {
                case 0:
                    $data->personastate = 'Offline';

The error was noted for

$this->player->name = (string) $data->steamID;

on line 213.

When I changed the config to use the API I was able to get passed this and the login worked again.
A little side-node is that in your readme you direct uses to the config file as: steam-auth.php but it's called steam-login.php. Just a little side-note.

BindingResolutionException while returning back from steam

Hi,

I'm new to Laravel and I think this error is more Laravel's issue than this module's but since I couldn't find the solution this problem anywhere so I'm creating an issue here.

I get this error when user logs in on steam and comes back to the website.
Illuminate \ Contracts \ Container \
BindingResolutionException
Unresolvable dependency resolving [Parameter #0 [ <required> $steamId ]] in class kanalumaddela\LaravelSteamLogin\SteamUser

You can view the error page from Laravel here. [I didn't know better way to share image 😅]

I have followed all the steps from your documentation. I know things are working because user can go to steam login page and when I remove 'auntheticate' method from 'SteamLoginController' class it says the method is missing while returning from steam.

Strange issue

I have a very strange issue, I explained it in this screenshot.
image
I tried setting the user data columns as nullable, but then it would just insert the steamid, username, and avatar as null. I'm not sure what's causing it and if you have a solution please let me know. Thank you!

compse -> composer*

compose require kanalumaddela/laravel-steam-login
composer require kanalumaddela/laravel-steam-login

"could not find driver"

I'm fairly certain (and yet uncertain at the same time, I am extremely new to using Laravel so I'm not sure what I could have done) this is an installation issue, and therefore something I did wrong, so I must apologize in advance. I followed the instructions, and even after doing some manual editing to the SteamLoginController (App\User gave me an error that said it "wasn't found", so I used "App\Models\User" which seemed to fix the issue), I landed upon a seemingly database related issue.

The setup says nothing about a specific database schema, although possibly that's implied and I'm too dense to realize that. That being said, after attempting to authorize I receive the QueryException "could not find driver (SQL: select * from users where steam_account_id = 393058422 limit 1)".

Again, I really apologize for my lack of understanding however I'm honestly not certain what to do about this. If you believe there's something I need to know/learn before using this repo, I'd love it if you'd direct me to that.

I have edited the .env file to the proper database settings, I believe.

Installation request for xpaw/steamid (locked at 1.0.1) -> satisfiable by xpaw/steamid[1.0.1].

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for xpaw/steamid (locked at 1.0.1) -> satisfiable by xpaw/steamid[1.0.1].
    - kanalumaddela/laravel-steam-login 2.4.0 requires xpaw/steamid dev-master -> satisfiable by xpaw/steamid[dev-master].
    - kanalumaddela/laravel-steam-login 2.x-dev requires xpaw/steamid dev-master -> satisfiable by xpaw/steamid[dev-master].
    - Conclusion: don't install xpaw/steamid dev-master
    - Installation request for kanalumaddela/laravel-steam-login ^2.4 -> satisfiable by kanalumaddela/laravel-steam-login[2.4.0, 2.x-dev].


Installation failed, reverting ./composer.json to its original content.

isLoggedIn

Is there a check to see if they are logged in?

Code example will be nice :)

Laravel 9.0

I dont can run it on Laravel 9.0, is it even compatible?

Error when installing with Laravel 7

Hello,
I'm trying to install this, but I'm getting an error when trying to.
image

I've ext-gmp enabled in my PHP, so I'm not so sure why this happens..

Bootstrap App giving me errors

Uncaught Error: Call to undefined method Illuminate\Foundation\Application::configure() in C:\laragon\www\test\bootstrap\app.php:30 Stack trace: #0 C:\laragon\www\test\public\index.php(38): require_once() #1 C:\laragon\www\test\server.php(21): require_once('C:\laragon\www\...') #2 {main} thrown in C:\laragon\www\test\bootstrap\app.php on line 30

Laravel Framework 7.13.0

image

Route [] not defined.

Hey, I am trying to access /login/steam, however, I'm getting a "InvalidArgumentException("Route [{$name}] not defined.");".

Here's my web.php:
SteamLogin::routes(['controller' => SteamLoginController::class]);

This is my SteamAuthController:
`namespace App\Http\Controllers\Auth;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use kanalumaddela\LaravelSteamLogin\Http\Controllers\AbstractSteamLoginController;
use kanalumaddela\LaravelSteamLogin\SteamUser;

class SteamLoginController extends AbstractSteamLoginController
{

/**
 * Where to redirect users after authenticating.
 *
 * @var string
 */
protected $redirectTo = '/';

/**
 * Logs the user out.
 *
 * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
 */
public function logout()
{
    // Logout and redirect user.
    return redirect($this->redirectTo)->with(Auth::logout());
}

/**
 * {@inheritdoc}
 */
public function authenticated(Request $request, SteamUser $steamUser)
{
    // Convert the steam64 to a hex with a "steam" prefix which is used in FiveM for identifying users.
    $identifier = 'steam:' . $this->steam64ToHex($steamUser->steamId);

    // Find the user by their identifier
    $user = User::where('identifier', $identifier)->first();

    if (is_null($user)) {
        // Create the user as they don't exist in the database.
        $user = $this->createUser($identifier, $steamUser->getUserInfo());
    }

    // Login with remember and redirect them.
    return redirect($this->redirectTo)->with(Auth::login($user, true));
}

/**
 * Getting user by info or create them if they do not exist.
 *
 * @param $identifier
 * @param $info
 * @return User
 */
protected function createUser($identifier, $info)
{
    // Create and return them.
    return User::create([
        'identifier' => $identifier,
        'avatar' => $info->avatar,
        'username' => $info->name,
    ]);
}

/**
 * Converts a steam64 identifier to hex which is more readable.
 *
 * @param $steam64
 * @return string
 */
private function steam64ToHex($steam64)
{
    // Convert decimal to hexadecimal.
    return dechex($steam64);
}

}`

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.