PHP code example of ziganshinalexey / yii2-steam-openid-auth
1. Go to this page and download the library: Download ziganshinalexey/yii2-steam-openid-auth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ziganshinalexey / yii2-steam-openid-auth example snippets
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.
}
$profileData = $this->getSteamApiComponent()->getProfile($profileId);