ziganshinalexey / yii2-steam-openid-auth
Steam认证管理子系统
1.0.0
2018-08-27 13:32 UTC
Requires
- php: ^7.2.0
- yiisoft/yii2: ^2.0.13
- yiisoft/yii2-authclient: ^2.1
This package is auto-updated.
Last update: 2024-09-05 05:36:17 UTC
README
该包是 yiisoft/yii2-authclient 的扩展,并添加了用于通过 OpenId 与 Steam 进行认证的类。
使用方法
控制器
class SiteController extends Controller { use SteamApiComponentTrait; . . . /** * Метод определяет конфигурацию экшенов текущего контроллера. * * @return array */ public function actions() { return [ . . . 'auth' => [ 'class' => SteamAuthAction::class, 'successCallback' => [ $this, 'auth', ], ], ]; } /** * Метод обработки успешной авторизации. * * @param SteamOpenId $openIdClient Клиент авторизации. * * @return void * * @throws InvalidConfigException Если стим гонит. */ public function auth(SteamOpenId $openIdClient): void { // Your action handle. For example: if (! isset($openIdClient->getUserAttributes()['id'])) { throw new InvalidConfigException('Bad steam response.'); } $openIdUrl = explode('/', $openIdClient->getUserAttributes()['id']); $profileId = array_pop($openIdUrl); $profileData = $this->getSteamApiComponent()->getProfile($profileId); var_dump($profileData); die; } . . . }
视图
use yii\authclient\widgets\AuthChoice; /* @var $this yii\web\View */ try { AuthChoice::widget([ 'baseAuthUrl' => ['site/auth'], 'popupMode' => false, ]); } catch (Exception $e) { // Your Catch handle. }
此外,该包还提供了操作 Steam API 的功能。
目前实现了获取用户资料的方法。
类
$profileData = $this->getSteamApiComponent()->getProfile($profileId);