#StackBounty: #performance #php #authentication #laravel #steam Steam Auth for Laravel

Bounty: 100

I’m not expert on OpenID, so i don’t know if my package is correct and safe. I’ve realized that after login on Steam community, take about 2/3 seconds to return to my page. It’s my issue or is from steam?

{
/**
 * The application instance.
 *
 * @var IlluminateContractsFoundationApplication
 */
private $app;
/**
 * The HTTP Client instance.
 *
 * @var GuzzleHttpClient
 */
private $httpClient;
/**
 * The custom parameters to be sent with the request.
 *
 * @var array
 */
private $parameters = [];
/**
 * The type of the encoding in the query.
 *
 * @var int Can be either PHP_QUERY_RFC3986 or PHP_QUERY_RFC1738.
 */
private $encodingType = PHP_QUERY_RFC3986;
/**
 * Create a new Steamlite manager instance.
 *
 * @param IlluminateContractsFoundationApplication $app
 * @return void
 */
public function __construct(Application $app)
{
    $this->app = $app;
}
/**
 * {@inheritdoc}
 */
public function redirect()
{
    return new RedirectResponse($this->getAuthUrl());
}
/**
 * {@inheritdoc}
 */
public function user()
{
    if ($this->hasInvalidSignature($query = $this->app['request']->query())) {
        throw new InvalidSignatureException();
    }
    return $this->mapUserToObject($this->getUserByToken($this->getAccessToken($query)));
}
/**
 * Get the raw user for the given access token.
 *
 * @param string $token
 * @return array
 */
private function getUserByToken($token)
{
    $userUrl = 'https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='.$this->app['config']['services.steam']['key'].'&steamids='.$token;
    $response = $this->getHttpClient()->get($userUrl);
    $user = json_decode($response->getBody(), true);
    return Arr::get($user, 'response.players.0');
}
/**
 * Map the raw user array to a User instance.
 *
 * @param array $user
 * @return Lai0nSteamliteUser
 */
private function mapUserToObject(array $user)
{
    return (new User)->setRaw($user)->map([
        'id' => $user['steamid'], 'nickname' => $user['personaname'], 'name' => Arr::get($user, 'realname', null),
        'avatar' => $user['avatar'], 'visibility' => $user['communityvisibilitystate'],
    ]);
}
/**
 * Parse the access token from identity url.
 *
 * @param array $query
 * @return string
 */
private function getAccessToken(array $query)
{
    preg_match('//id/(d+)$/i', $query['openid_identity'], $matches);
    return $matches[1];
}
/**
 * Get the URL for the steam authentication screen.
 *
 * @return string
 */
private function getAuthUrl()
{
    return $this->buildAuthUrl('https://steamcommunity.com/openid/login');
}
/**
 * Build the authentication URL with the OpenID and custom parameters.
 *
 * @param string $url
 * @return string
 */
private function buildAuthUrl($url)
{
    return $url.'?'.http_build_query($this->getCodeFields(), '', '&', $this->encodingType);
}
/**
 * Get the GET parameters for the code request.
 *
 * @return array
 */
private function getCodeFields()
{
    $fields = [
        'openid.ns' => 'http://specs.openid.net/auth/2.0',
        'openid.mode' => 'checkid_setup',
        'openid.realm' => $this->app['config']['app.url'],
        'openid.return_to' => $this->app['config']['services.steam']['redirect'],
        'openid.identity' => 'http://specs.openid.net/auth/2.0/identifier_select',
        'openid.claimed_id' => 'http://specs.openid.net/auth/2.0/identifier_select',
    ];
    return array_merge($fields, $this->parameters);
}
/**
 * Determine if the current request has a mismatching signature.
 *
 * @param array $query
 * @return bool
 */
private function hasInvalidSignature(array $query)
{
    $postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';
    $response = $this->getHttpClient()->post('https://steamcommunity.com/openid/login', [
        $postKey => $this->getCheckAuthFields($query)
    ]);
    return preg_match('/is_valids*:s*false/i', $response->getBody());
}
/**
 * Get the fields for check authentication.
 *
 * @param array $query
 * @return array
 */
private function getCheckAuthFields(array $query)
{
    $fields = [];
    foreach ($query as $index => $item) {
        $position = strpos($index, '_');
        if ($position !== false) {
            $index = substr_replace($index, '.', $position, strlen('_'));
        }
        $fields[$index] = $item;
    }
    $fields['openid.mode'] = 'check_authentication';
    return $fields;
}
/**
 * Get a instance of the Guzzle HTTP client.
 *
 * @return GuzzleHttpClient
 */
private function getHttpClient()
{
    if (is_null($this->httpClient)) {
        $this->httpClient = new Client();
    }
    return $this->httpClient;
}
/**
 * Set the Guzzle HTTP client instance.
 *
 * @param GuzzleHttpClient $client
 * @return $this
 */
public function setHttpClient(Client $client)
{
    $this->httpClient = $client;
    return $this;
}
/**
 * Set the custom parameters of the request.
 *
 * @param array $parameters
 * @return $this
 */
public function with(array $parameters)
{
    $this->parameters = $parameters;
    return $this;
}


Get this bounty!!!