Я использую:
"php": "^ 7.2.5", "laravel / framework": "^ 7.0", "laravel / socialite": "^ 4.4", "socialiteproviders / steam": "^ 3.0"
Попытка расширить \SocialiteProviders\Steam\Provider
:
namespace App\Services\NetworkSync;
use Laravel\Socialite\Two\User;
use Illuminate\Support\Arr;
use SocialiteProviders\Steam\Provider;
use Illuminate\Support\Facades\Log;
class SteamService extends Provider
{
const OPENID_SIG = 'openid.sig';
const OPENID_SIGNED = 'openid.signed';
const OPENID_ASSOC_HANDLE = 'openid.assoc_handle';
const OPENID_ERROR = 'openid.error';
protected function mapUserToObject(array $user)
{
return (new User())->setRaw($user)->map([
'id' => $user['steamid'],
'nickname' => Arr::get($user, 'personaname'),
'name' => Arr::get($user, 'realname'),
'email' => null,
'avatar' => Arr::get($user, 'avatarmedium'),
]);
}
public function user()
{
//Log::debug($this->getDefaultRequestOptions());
Log::debug($this->getConfig('api_key'));
if (!$this->validate()) {
$error = $this->getParams()['openid.error'] ?? 'unknown error';
throw new OpenIDValidationException('Failed to validate OpenID login: '.$error);
}
return $this->mapUserToObject($this->getUserByToken($this->steamId));
}
public function getParams()
{
$params = [
'openid.assoc_handle' => $this->request->get(self::OPENID_ASSOC_HANDLE),
'openid.signed' => $this->request->get(self::OPENID_SIGNED),
'openid.sig' => $this->request->get(self::OPENID_SIG),
'openid.ns' => self::OPENID_NS,
'openid.mode' => 'check_authentication',
'openid.error' => $this->request->get(self::OPENID_ERROR),
];
$signedParams = explode(',', $this->request->get(self::OPENID_SIGNED));
foreach ($signedParams as $item) {
$value = $this->request->get('openid.'.str_replace('.', '_', $item));
$params['openid.'.$item] = $value;
}
return $params;
}
public function parseSteamID()
{
preg_match(
'#^https?://steamcommunity.com/openid/id/([0-9]{17,25})#',
$this->request->get('openid.claimed_id'),
$matches
);
$this->steamId = is_numeric($matches[1]) ? $matches[1] : 0;
}
}
Определение собственного менеджера:
namespace App\Services;
use Laravel\Socialite\SocialiteManager;
use App\Services\NetworkSync\SteamService;
class NetworkSyncService extends SocialiteManager
{
public function createSteamDriver()
{
$config = $this->app['config']['services.steam'];//Config is valid
return $this->buildProvider(SteamService::class, $config);
}
}
И я установил его в контейнере:
namespace App\Providers;
use Laravel\Socialite\SocialiteServiceProvider;
use App\Services\NetworkSyncService;
class NetworkSyncProvider extends SocialiteServiceProvider
{
public function register()
{
$this->app->singleton('Laravel\Socialite\Contracts\Factory', function ($app) {
return new NetworkSyncService($app);
});
}
}
Все нормально, все работает, но конфиг не передается, $this->getConfig('api_key') === null
. Также я пытался сделать как здесь https://github.com/JaffParker/Extending-Laravel-Socialite, но результат такой же. В чем может быть проблема?