• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
  • This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

SteamCommunity integration (like FaceBook)

Jesepi

Well-known member
#2
I would like this as my community is PC gaming focused, and almost everyone has a steam account.

http://steamcommunity.com/dev :
Steam can act as an OpenID provider. This allows your application to authenticate a user's SteamID without requiring them to enter their Steam username or password on your site (which would be a violation of the API Terms of Use.) Just download an OpenID library for your language and platform of choice and use http://steamcommunity.com/openid as the provider. The returned Claimed ID will contain the user's 64-bit SteamID. The Claimed ID format is: http://steamcommunity.com/openid/id/<steamid>
 
#3
This would require OpenID. I have found a script that does it, but I haven't looked trough it yet, so not sure if it would work on XF. Zend haves something on OpenID though.

PHP:
<?php
/**
*
* @package Steam Community API
* @copyright (c) 2010 ichimonai.com
* @license http://opensource.org/licenses/mit-license.php The MIT License
*
*/

class SteamSignIn
{
    const STEAM_LOGIN = 'https://steamcommunity.com/openid/login';

    /**
    * Get the URL to sign into steam
    *
    * @param mixed returnTo URI to tell steam where to return, MUST BE THE FULL URI WITH THE PROTOCOL
    * @param bool useAmp Use &amp; in the URL, true; or just &, false.
    * @return string The string to go in the URL
    */
    public static function genUrl($returnTo = false, $useAmp = true)
    {
        $returnTo = (!$returnTo) ? (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] : $returnTo;

        $params = array(
            'openid.ns'            => 'http://specs.openid.net/auth/2.0',
            'openid.mode'        => 'checkid_setup',
            'openid.return_to'    => $returnTo,
            'openid.realm'        => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'],
            'openid.identity'    => 'http://specs.openid.net/auth/2.0/identifier_select',
            'openid.claimed_id'    => 'http://specs.openid.net/auth/2.0/identifier_select',
        );

        $sep = ($useAmp) ? '&amp;' : '&';
        return self::STEAM_LOGIN . '?' . http_build_query($params, '', $sep);
    }

    /**
    * Validate the incoming data
    *
    * @return string Returns the SteamID64 if successful or empty string on failure
    */
    public static function validate()
    {
        // Star off with some basic params
        $params = array(
            'openid.assoc_handle'    => $_GET['openid_assoc_handle'],
            'openid.signed'            => $_GET['openid_signed'],
            'openid.sig'            => $_GET['openid_sig'],
            'openid.ns'                => 'http://specs.openid.net/auth/2.0',
        );

        // Get all the params that were sent back and resend them for validation
        $signed = explode(',', $_GET['openid_signed']);
        foreach($signed as $item)
        {
            $val = $_GET['openid_' . str_replace('.', '_', $item)];
            $params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($val) : $val;
        }

        // Finally, add the all important mode.
        $params['openid.mode'] = 'check_authentication';

        // Stored to send a Content-Length header
        $data =  http_build_query($params);
        $context = stream_context_create(array(
            'http' => array(
                'method'  => 'POST',
                'header'  =>
                    "Accept-language: en\r\n".
                    "Content-type: application/x-www-form-urlencoded\r\n" .
                    "Content-Length: " . strlen($data) . "\r\n",
                'content' => $data,
            ),
        ));

        $result = file_get_contents(self::STEAM_LOGIN, false, $context);

        // Validate wheather it's true and if we have a good ID
        preg_match("#^http://steamcommunity.com/openid/id/([0-9]{17,25})#", $_GET['openid_claimed_id'], $matches);
        $steamID64 = is_numeric($matches[1]) ? $matches[1] : 0;

        // Return our final value
        return preg_match("#is_valid\s*:\s*true#i", $result) == 1 ? $steamID64 : '';
    }
}
 
#5
This would require OpenID. I have found a script that does it, but I haven't looked trough it yet, so not sure if it would work on XF. Zend haves something on OpenID though.

PHP:
<?php
/**
*
* @package Steam Community API
* @copyright (c) 2010 ichimonai.com
* @license http://opensource.org/licenses/mit-license.php The MIT License
*
*/

class SteamSignIn
{
    const STEAM_LOGIN = 'https://steamcommunity.com/openid/login';

    /**
    * Get the URL to sign into steam
    *
    * @param mixed returnTo URI to tell steam where to return, MUST BE THE FULL URI WITH THE PROTOCOL
    * @param bool useAmp Use &amp; in the URL, true; or just &, false.
    * @return string The string to go in the URL
    */
    public static function genUrl($returnTo = false, $useAmp = true)
    {
        $returnTo = (!$returnTo) ? (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] : $returnTo;

        $params = array(
            'openid.ns'            => 'http://specs.openid.net/auth/2.0',
            'openid.mode'        => 'checkid_setup',
            'openid.return_to'    => $returnTo,
            'openid.realm'        => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'],
            'openid.identity'    => 'http://specs.openid.net/auth/2.0/identifier_select',
            'openid.claimed_id'    => 'http://specs.openid.net/auth/2.0/identifier_select',
        );

        $sep = ($useAmp) ? '&amp;' : '&';
        return self::STEAM_LOGIN . '?' . http_build_query($params, '', $sep);
    }

    /**
    * Validate the incoming data
    *
    * @return string Returns the SteamID64 if successful or empty string on failure
    */
    public static function validate()
    {
        // Star off with some basic params
        $params = array(
            'openid.assoc_handle'    => $_GET['openid_assoc_handle'],
            'openid.signed'            => $_GET['openid_signed'],
            'openid.sig'            => $_GET['openid_sig'],
            'openid.ns'                => 'http://specs.openid.net/auth/2.0',
        );

        // Get all the params that were sent back and resend them for validation
        $signed = explode(',', $_GET['openid_signed']);
        foreach($signed as $item)
        {
            $val = $_GET['openid_' . str_replace('.', '_', $item)];
            $params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($val) : $val;
        }

        // Finally, add the all important mode.
        $params['openid.mode'] = 'check_authentication';

        // Stored to send a Content-Length header
        $data =  http_build_query($params);
        $context = stream_context_create(array(
            'http' => array(
                'method'  => 'POST',
                'header'  =>
                    "Accept-language: en\r\n".
                    "Content-type: application/x-www-form-urlencoded\r\n" .
                    "Content-Length: " . strlen($data) . "\r\n",
                'content' => $data,
            ),
        ));

        $result = file_get_contents(self::STEAM_LOGIN, false, $context);

        // Validate wheather it's true and if we have a good ID
        preg_match("#^http://steamcommunity.com/openid/id/([0-9]{17,25})#", $_GET['openid_claimed_id'], $matches);
        $steamID64 = is_numeric($matches[1]) ? $matches[1] : 0;

        // Return our final value
        return preg_match("#is_valid\s*:\s*true#i", $result) == 1 ? $steamID64 : '';
    }
}
How to add openid to XenForo? :D
 
#7
yep .. bunch of us have been asking for this for a while
... and you may interested that the administrator for steam community forums has been known to post here :)
 
#8
oh btw,
I have steamid as a user field, and I have steam badge in my "post bit", but have never figured out openid (plus I disabled the twitter auth coz no one was using it)
 
#12
This would require OpenID. I have found a script that does it, but I haven't looked trough it yet, so not sure if it would work on XF. Zend haves something on OpenID though.

PHP:
<?php
/**
*
* @package Steam Community API
* @copyright (c) 2010 ichimonai.com
* @license http://opensource.org/licenses/mit-license.php The MIT License
*
*/

class SteamSignIn
{
    const STEAM_LOGIN = 'https://steamcommunity.com/openid/login';

    /**
    * Get the URL to sign into steam
    *
    * @param mixed returnTo URI to tell steam where to return, MUST BE THE FULL URI WITH THE PROTOCOL
    * @param bool useAmp Use &amp; in the URL, true; or just &, false.
    * @return string The string to go in the URL
    */
    public static function genUrl($returnTo = false, $useAmp = true)
    {
        $returnTo = (!$returnTo) ? (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] : $returnTo;

        $params = array(
            'openid.ns'            => 'http://specs.openid.net/auth/2.0',
            'openid.mode'        => 'checkid_setup',
            'openid.return_to'    => $returnTo,
            'openid.realm'        => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'],
            'openid.identity'    => 'http://specs.openid.net/auth/2.0/identifier_select',
            'openid.claimed_id'    => 'http://specs.openid.net/auth/2.0/identifier_select',
        );

        $sep = ($useAmp) ? '&amp;' : '&';
        return self::STEAM_LOGIN . '?' . http_build_query($params, '', $sep);
    }

    /**
    * Validate the incoming data
    *
    * @return string Returns the SteamID64 if successful or empty string on failure
    */
    public static function validate()
    {
        // Star off with some basic params
        $params = array(
            'openid.assoc_handle'    => $_GET['openid_assoc_handle'],
            'openid.signed'            => $_GET['openid_signed'],
            'openid.sig'            => $_GET['openid_sig'],
            'openid.ns'                => 'http://specs.openid.net/auth/2.0',
        );

        // Get all the params that were sent back and resend them for validation
        $signed = explode(',', $_GET['openid_signed']);
        foreach($signed as $item)
        {
            $val = $_GET['openid_' . str_replace('.', '_', $item)];
            $params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($val) : $val;
        }

        // Finally, add the all important mode.
        $params['openid.mode'] = 'check_authentication';

        // Stored to send a Content-Length header
        $data =  http_build_query($params);
        $context = stream_context_create(array(
            'http' => array(
                'method'  => 'POST',
                'header'  =>
                    "Accept-language: en\r\n".
                    "Content-type: application/x-www-form-urlencoded\r\n" .
                    "Content-Length: " . strlen($data) . "\r\n",
                'content' => $data,
            ),
        ));

        $result = file_get_contents(self::STEAM_LOGIN, false, $context);

        // Validate wheather it's true and if we have a good ID
        preg_match("#^http://steamcommunity.com/openid/id/([0-9]{17,25})#", $_GET['openid_claimed_id'], $matches);
        $steamID64 = is_numeric($matches[1]) ? $matches[1] : 0;

        // Return our final value
        return preg_match("#is_valid\s*:\s*true#i", $result) == 1 ? $steamID64 : '';
    }
}
I found how to use it :)

PHP:
$steam_login_verify = SteamSignIn::validate();
if(!empty($steam_login_verify))
{
echo "success + $steam_login_verify";
}
else
{
$steam_sign_in_url = SteamSignIn::genUrl();
echo "<a href=\"$steam_sign_in_url\"><img src='http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_noborder.png' /></a>";
}
Now i need to find how to add this in XenForo, so it will work like FaceBook integration :)
 
#13
I found how to use it :)

PHP:
$steam_login_verify = SteamSignIn::validate();
if(!empty($steam_login_verify))
{
echo "success + $steam_login_verify";
}
else
{
$steam_sign_in_url = SteamSignIn::genUrl();
echo "<a href=\"$steam_sign_in_url\"><img src='http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_noborder.png' /></a>";
}
Now i need to find how to add this in XenForo, so it will work like FaceBook integration :)
I'll see what I can do when I get my XenForo back...
 
#14

yep .. bunch of us have been asking for this for a while
... and you may interested that the administrator for steam community forums has been known to post here :)

Lies! :p

oh btw,
I have steamid as a user field, and I have steam badge in my "post bit", but have never figured out openid (plus I disabled the twitter auth coz no one was using it)
Simple way:

Step 1: Find an OpenID library you like
Step 2: Create a Xenforo page where a user clicks the "login with Steam" button and perform the actual OAuth authentication
Step 3: Take the returned data, extract the 64bit SteamID, and write that to a new column in the User table

That is the easy part. You will then need to update the login and account creation system to handle Steam OAuth logins. And if you want to get really fancy, you write a class that leverages the Steam web apis and replace forum avatars with Steam community avatars, forum usernames with Steam personas, show ingame status, etc.

All work I'm planning to do but not until we upgrade our forums to vb4.

But if Mike and Kier wanted to do the hard work for me, thats just one more reason for us to switch :)