fuziion/riot-games-sso 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

fuziion/riot-games-sso

最新稳定版本:v1.0.0

Composer 安装命令:

composer require fuziion/riot-games-sso

包简介

A simple and efficient PHP package for implementing Riot Games SSO authentication. Works with any PHP framework (Laravel, Symfony, CodeIgniter) or plain PHP projects.

README 文档

README

Latest Version Total Downloads License

A simple and efficient PHP package for implementing Riot Games SSO (Single Sign-On) authentication. Works with any PHP project including Laravel, Symfony, CodeIgniter, or plain PHP. This package uses native PHP cURL, requiring no external HTTP client dependencies.

Features

  • Zero Dependencies - Uses native PHP cURL, no Guzzle or other HTTP clients required
  • Laravel Integration - Seamless integration with Laravel via Service Provider and Facade
  • Framework Agnostic - Can be used in any PHP project
  • Simple API - Clean and intuitive methods for OAuth flow
  • Error Handling - Comprehensive exception handling
  • Type Safe - Full type hints and return types

Installation

Install the package via Composer:

composer require fuziion/riot-games-sso

Quick Start

Plain PHP / Framework Agnostic Usage

The package works out of the box in any PHP project. Simply instantiate the class with your credentials:

💡 Tip: See EXAMPLE_STANDALONE.php for a complete working example in a standalone PHP project.

require 'vendor/autoload.php';

use Fuziion\RiotGamesSSO\RiotGames;
use Fuziion\RiotGamesSSO\Exceptions\RiotGamesException;

// Initialize with your credentials
$riotGames = new RiotGames(
    clientId: 'your_client_id',
    clientSecret: 'your_client_secret'
);

try {
    // Step 1: Get authorization URL and redirect user
    $authUrl = $riotGames->getAuthorizationUrl('https://yourapp.com/callback');
    header("Location: {$authUrl}");
    exit;
    
    // Step 2: Handle callback (after user authorizes)
    $code = $_GET['code'] ?? null;
    if ($code) {
        $accessToken = $riotGames->getRiotAuthToken($code, 'https://yourapp.com/callback');
        
        if ($accessToken) {
            $accountData = $riotGames->getRiotAccountData($accessToken);
            $accountData['puuid'] - Player UUID
            $accountData['gameName'] - In-game name
            $accountData['tagLine'] - Tag line
        }
    }
} catch (RiotGamesException $e) {
    echo "Error: " . $e->getMessage();
}

Laravel Setup

  1. Publish the configuration file (optional):
php artisan vendor:publish --tag=riot-games-sso-config
  1. Add your Riot Games credentials to your .env file:
RIOT_GAMES_CLIENT_ID=your_client_id
RIOT_GAMES_CLIENT_SECRET=your_client_secret

The service provider and facade are auto-discovered, so no manual registration is needed.

Usage

Laravel Usage

Using the Facade

use Fuziion\RiotGamesSSO\Facades\RiotGames;

// Redirect user to Riot Games login
public function redirectToRiot()
{
    $callbackUrl = route('riot.callback');
    return redirect(RiotGames::getAuthorizationUrl($callbackUrl));
}

// Handle the callback
public function handleCallback(Request $request)
{
    try {
        $code = $request->get('code');
        $callbackUrl = route('riot.callback');
        
        // Exchange code for access token
        $accessToken = RiotGames::getRiotAuthToken($code, $callbackUrl);
        
        if ($accessToken) {
            // Get user account data
            $accountData = RiotGames::getRiotAccountData($accessToken);
            
            // $accountData contains:
            // - puuid: Player UUID
            // - gameName: In-game name
            // - tagLine: Tag line
            
            // Handle user authentication/login here
            // ...
        }
    } catch (\Fuziion\RiotGamesSSO\Exceptions\RiotGamesException $e) {
        // Handle error
        return redirect()->back()->with('error', $e->getMessage());
    }
}

Using Dependency Injection

use Fuziion\RiotGamesSSO\RiotGames;

class RiotAuthController extends Controller
{
    public function __construct(
        protected RiotGames $riotGames
    ) {}
    
    public function redirectToRiot()
    {
        $callbackUrl = route('riot.callback');
        return redirect($this->riotGames->getAuthorizationUrl($callbackUrl));
    }
    
    public function handleCallback(Request $request)
    {
        $code = $request->get('code');
        $callbackUrl = route('riot.callback');
        
        $accessToken = $this->riotGames->getRiotAuthToken($code, $callbackUrl);
        $accountData = $this->riotGames->getRiotAccountData($accessToken);
        
        // Handle authentication...
    }
}

Other PHP Frameworks (Symfony, CodeIgniter, etc.)

The package works the same way in any PHP framework. Just instantiate the class with your credentials:

use Fuziion\RiotGamesSSO\RiotGames;
use Fuziion\RiotGamesSSO\Exceptions\RiotGamesException;

// In your controller or service
$riotGames = new RiotGames(
    clientId: getenv('RIOT_GAMES_CLIENT_ID'),
    clientSecret: getenv('RIOT_GAMES_CLIENT_SECRET')
);

// Get authorization URL
$authUrl = $riotGames->getAuthorizationUrl('https://yourapp.com/callback');

// Exchange code for token
$accessToken = $riotGames->getRiotAuthToken($code, $redirectUri);

// Get account data
$accountData = $riotGames->getRiotAccountData($accessToken);

API Reference

Methods

getAuthorizationUrl(string $redirectUri, array $scopes = ['openid', 'offline_access', 'email']): string

Generate the authorization URL for redirecting users to Riot Games login.

Parameters:

  • $redirectUri - The callback URL where Riot will redirect after authentication
  • $scopes - Optional array of OAuth scopes (default: openid, offline_access, email)

Returns: The full authorization URL

getRiotAuthToken(string $code, string $redirectUri): string|null

Exchange the authorization code for an access token.

Parameters:

  • $code - The authorization code from the callback
  • $redirectUri - The redirect URI used in the authorization request (must match exactly)

Returns: The access token or null if not found

Throws: RiotGamesException on error

getRiotAccountData(string $accessToken): array

Get user account data using the access token.

Parameters:

  • $accessToken - The OAuth access token

Returns: Array containing:

  • puuid - Player UUID
  • gameName - In-game name
  • tagLine - Tag line

Throws: RiotGamesException on error

Example Routes (Laravel)

// routes/web.php
Route::get('/auth/riot', [RiotAuthController::class, 'redirectToRiot'])->name('riot.login');
Route::get('/auth/riot/callback', [RiotAuthController::class, 'handleCallback'])->name('riot.callback');

Error Handling

The package throws RiotGamesException for all errors. Always wrap calls in try-catch blocks:

use Fuziion\RiotGamesSSO\Exceptions\RiotGamesException;

try {
    $accessToken = RiotGames::getRiotAuthToken($code, $redirectUri);
} catch (RiotGamesException $e) {
    // Handle error
    // $e->getMessage() contains the error message
    // $e->getCode() contains the HTTP status code (if applicable)
}

Requirements

  • PHP 8.1 or higher
  • cURL extension enabled
  • Riot Games Developer Account with OAuth credentials

Getting Riot Games Credentials

  1. Visit the Riot Games Developer Portal
  2. Create a new application
  3. Configure your redirect URI
  4. Copy your Client ID and Client Secret

License

This package is open-sourced software licensed under the MIT license.

Author

Diederik Veenstra (fuziion_dev)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固