Jump to content

So Guys, I wanted to use OpenID so people can login using steam but there are no good tutorials online (all are outdated) and the OpenID has no documentation. I am using the OpenID-Connect-PHPIf anyone knows how to do it with this then please help me.

Thanks.

I like potatoes, if you don't then please just step aside and let me enjoy this potato.

Link to comment
https://linustechtips.com/topic/495264-steam-openid/
Share on other sites

Link to post
Share on other sites

I don't know how about your link, but I can introduce you an example built on LightOpenId lib, which you can find here: https://github.com/iignatov/LightOpenID

<?php	require_once('OpenID.php');		session_start();		if(isset($_GET['logout']) && isset($_SESSION['LOGINDATA'])){ // I check if login data is set to display "logged out" message only once.		echo 'You has been logged out.<br/>';		session_unset();	}			//This part is about OpenId and is the most important to understand.	if(!isset($_SESSION['LOGINDATA'])){		try {			$openid = new LightOpenID('https://pehape-mr-koka.c9users.io/'); //This is root url used to generate return url, so the url you will be redirected after click "sign in" on steam.			$openid->identity = 'http://steamcommunity.com/openid';			$openid->returnUrl = 'https://pehape-mr-koka.c9users.io/'; // This changes return url to root url of site, without setting (overwritting) this property, after login you will be returned to url where authUrl was generated.						$displayLogin = true;						if($openid->mode == 'cancel'){				echo 'Login canceled.<br/>';			} else if($openid->mode == 'error'){				echo 'Login error.<br/>';			} else if($openid->mode == 'id_res') {				if($openid->validate()){					//Parse steamid from identity steam returns.					$re = '/openid\/id\/([0-9]+)$/'; 					if(preg_match($re, $openid->identity, $matches)){						$_SESSION['LOGINDATA'] = $matches[1];							$displayLogin = false;					} else {						echo 'Unsuported identity format, steamid not found.';					}				} else {					echo 'Login failed!<br/>';				}			} else if($openid->mode){ //Just in case, to discover modes I don't know of, and maybe handle them.				echo 'Unsoported mode: '.$openid->mode.'<br/>';			}						if($displayLogin){				echo '<a href="'.$openid->authUrl().'">login</a><br/>';			}		} catch(Exception $e){			echo 'Error has occurred. '. $e->getMessage();		}	} 		if(isset($_SESSION['LOGINDATA'])){		/*		* This is part where we are already logged in		* If your site need assing data with logged steam id now is time to check if account exists and create account db entry if it doesn't.		*/		echo 'Hello, your Steam id is: '.$_SESSION['LOGINDATA'].'<br/>';		echo '<a href="?logout=true">Logout</a><br/>';				/*		* Now when we have steamid, we can use SteamAPI (you need api key) http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=YOURSTEAMAPIKEY&steamids=STEAMID to		* retrieve some basic informations, or use xml to get more of informations from users profile. SteamAPI response looks like this:				{			"response": {				"players": [					{						"steamid": "76561197995773793",						"communityvisibilitystate": 3,						"profilestate": 1,						"personaname": "KoKa",						"lastlogoff": 1448801107,						"profileurl": "http://steamcommunity.com/id/mr_koka/",						"avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/17/170ad9e472e41e1e182fc786fa3974ce1b333c6c.jpg",						"avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/17/170ad9e472e41e1e182fc786fa3974ce1b333c6c_medium.jpg",						"avatarfull": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/17/170ad9e472e41e1e182fc786fa3974ce1b333c6c_full.jpg",						"personastate": 1,						"primaryclanid": "103582791432125620",						"timecreated": 1200260938,						"personastateflags": 0					}				]							}		}				* and XML you can see entering this link:				http://steamcommunity.com/profiles/76561197995773793/?xml=1				*/				/*		* This is only basic example, you would need to handle privacy of profile (some data is not available if profile is private, 		* but you will always have access to login and avatar) and probably use cache to not request those data by curl every page reload, that would be slow or/and expensive.		* This part is just for fun but you may need it		*/				$ch = curl_init('http://steamcommunity.com/profiles/'.$_SESSION['LOGINDATA'].'/?xml=1');		if($ch){			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // This one is important, cause steam profiles/STEAMID/?xml=1 url redirests to id/LOGIN/?xml=1 and we need to follow.			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);			$response = curl_exec($ch);						if($response !== FALSE){				$xmlParser = xml_parser_create();				if(xml_parse_into_struct($xmlParser, $response, $values, $indexes) == 1){					echo '<a href="'.$_SESSION['LOGINDATA'].'"><img src="'.$values[$indexes['AVATARMEDIUM'][0]]['value'].'"/></a><br/>'.$values[$indexes['STEAMID'][0]]['value'].'<br/>';				} else {					echo 'Unable to parse XML.';				}				xml_parser_free($xmlParser);			} else {				echo 'cURL request failed.<br/>';			}		} else {			echo 'Unable to initialize cURL.<br/>';		}	}

You may want to copy all above code tag contents and paste it somewhere where is no line word wrapping.

Link to comment
https://linustechtips.com/topic/495264-steam-openid/#findComment-6628311
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×