One of SteemNova most important goals is Steem blockchain integration. The vision of authors is to restrict this game for Steemians only. This way we can control weekly SBD rewards to best players and maybe limit some multiaccounts in the future. Below article describes how SteemConnect login authentication has been implemented to SteemNova.
SteemConnect v2 API
SteemConnect requires special type of account to log in through. For its purposes account has been created.
public static function getLoginUrl()
{
return 'https://v2.steemconnect.com/oauth2/authorize?client_id=' . self::$CLIENT_ID . '&redirect_uri=' . HTTP_PATH.'index.php&scope=' . self::$SCOPE;
}
Login and authentication
For the purposes of new authorization type, the Login Page has been refreshed.
protected function login()
{
$authstr = "authorization: " . $this->access_token;
$check = curl_init();
curl_setopt_array($check, array(
CURLOPT_URL => "https://v2.steemconnect.com/api/me",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 1,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{}",
CURLOPT_HTTPHEADER => array(
$authstr,
"cache-control: no-cache",
"content-type: application/json",
),
));
$result = curl_exec($check);
curl_close($check);
$_result = json_decode($result);
if(isset($_result->user)) {
$this->data = $_result;
return $_result->user;
} else {
return false;
}
}
Additionally, admins can log in to Admin Panel through SteemConnect too!
Account registration
Classic login:password registration has been disabled. Old accounts can still login via password but in the future it will be turned off.
Steemians can register to game through SteemConnect. If they have no in game account yet, it will be created automatically. Just log in and voila!
if(empty($loginData))
$authObj->register();
...
public function register()
{
global $LNG;
list($userId, $planetId) = PlayerUtil::createPlayer(
Universe::current(),
$this->scObj->getUser(),
'',
'',
$LNG->getLanguage());
return $userId;
}
Security
As account authentication needs only 'login' privilege (scope), only private MEMO key is needed to log in. Of course any private key can be used, but not needed.
SteemConnect button design-pack
Thanks to Andrej Cibík , his SteemConnect button .css style has been used. It is imported from
SteemConnect Design Pack repo
Screenshots
To prove successful authentication of user, his Steem avatar is drawn at the top of navigation bar.
Information
steemnova/steemnova project is fork of jkroepke/2Moons Open Source Browsergame Framework. The goal is to fix bugs and develop the engine in the direction of maximum Steem integration.
Links
- [Pull request] https://github.com/steemnova/steemnova/pull/67
- [SteemConnect API] https://v2.steemconnect.com/
- [SteemConnect Design Pack] https://github.com/noisy/steemconnect-design-pack
Posted on Utopian.io - Rewarding Open Source Contributors