danielburger1337/steam-openid

Steam的一个简单、现代且模块化的OpenID客户端库实现。

v1.2.0 2023-08-06 05:46 UTC

This package is auto-updated.

Last update: 2024-09-19 05:10:08 UTC


README

PHPUnit PHPStan

Steam OpenID认证库

Steam的一个简单、现代且模块化的OpenID客户端库实现。

为什么使用这个库?

这个库旨在让使用Steam进行OpenID认证的过程尽可能简单。

正如你可能知道的,已经有几个库或多或少地做了这个库所做的事情

但你可能知道或会看到,这些库正是人们讨厌PHP的原因。它们没有使用真正的编码或php-fig (psr)标准,不是模块化的(需要cURL),并且通常很难使用,因为它们不抛出异常。

如何使用

<?php declare(strict_types=1);

use danielburger1337\SteamOpenId\SteamOpenID;

// RECOMMENDATION: register this in your psr-11 container.
$openId = new SteamOpenID(
    // REQUIRED: your OpenID "realm" (your host)
    'http://localhost:5000',
    // REQUIRED: your OpenID "return_to" URI (your callback URI)
    'http://localhost:5000/Callback.php',
    // OPTIONAL: your psr-18 implementation (defaults to symfony/http-client)
    new GuzzleHttp\Client(),
    // OPTIONAL: your psr-17 implementation (default to nyholm/psr7)
    new Nyholm\Psr7\Factory\Psr17Factory()
);

// start the authentication flow by redirecting the user to Steam.
header('Location: ' . $openId->constructCheckIdSetupUri());

// ... in Callback.php (or your callback controller method)

use danielburger1337\SteamOpenId\Exception\ExceptionInterface;

// When steam redirects the user back to your "return_to" URI,
// verify the provided parameters in the query string.

try {
    // This method returns the users 64-bit SteamID.
    $steamId = $openId->verifyCallback($_GET);
} catch (ExceptionInterface $e) {
    exit(var_dump('Failed to verify steam authentication :('));
}

条款和条件

在使用此库之前,请阅读并接受Valve的条款和条件这里