Skip to content

Commit

Permalink
First shot at auth against steamcommunity.com.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 3, 2010
1 parent d6fd7a5 commit 8cce2ef
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 4 deletions.
81 changes: 81 additions & 0 deletions auth.php
@@ -0,0 +1,81 @@
<?php

header("HTTP/1.0 307 Temporary redirect");
header('Content-type: text/plain; charset=UTF-8');

start_session();

if (isset($_GET['logout']))
{
header('Location: /');
unset($_SESSION['steamid']);
session_unset();
session_destroy();
print("We have now forgotten your SteamID.\n");
print("You'll have to log in to use this site again.\n\n");
exit(0);
} // if

if (isset($_SESSION['steamid']))
{
// Already logged in.
header('Location: /');
exit(0);
} // if

require_once('openid.php');

if (!isset($_GET['openid_mode']))
{
$url = 'http://steamcommunity.com/openid';
try
{
$openid = new LightOpenID;
$openid->identity = $url;
header('Location: ' . $openid->authUrl());
print("Redirecting you to Steam Community OpenID provider:\n");
print(" $url\n\n");
} // try
catch (ErrorException $e)
{
$msg = $e->getMessage();
print("OpenID library threw an exception:\n $msg\n\n");
header('Location: /');
} // catch
exit(0);
} // if

header('Location: /'); // always going here now.

if ($_GET['openid_mode'] == 'cancel')
print("User has canceled authentication!\n\n");
else
{
$okay = false;
try
{
$openid = new LightOpenID;
$okay = openid->validate();
} // try
catch (ErrorException $e)
{
$msg = $e->getMessage();
print("OpenID library threw an exception:\n $msg\n\n");
} // catch

$m = array();
if (!$okay)
print("User has not logged in!\n\n");
else if (!preg_match('/^.*\/(\d+)$/', $_GET['openid_identity'], $m))
print("User logged in, but we can't figure out SteamID!\n\n");
else
{
$steamid = $m[1];
$_SESSION['steamid'] = $steamid;
print("User logged in! SteamID is $steamid!\n\n");
} // else
} // else

exit(0);

?>
15 changes: 15 additions & 0 deletions index.html
Expand Up @@ -48,6 +48,12 @@
function process_steam_profile(xml)
{
var prof = $(xml).find('profile');
if (prof.find('steamid').text() == '0')
{
$('div.loginpopover').show();
return null;
} // if

if (prof.find('valid').text() != '1')
return null;

Expand Down Expand Up @@ -120,6 +126,15 @@
</script>
</head>
<body>
<div class='loginpopover'>
<center>
<p>You need to login to Steam Community to access this page.</p>
<p>We are forwarding you to steamcommunity.com.</p>
<p>Your password will only be supplied to the Steam website and not
to this one.</p>
<p><a href='auth.php'>Go there now.</a></p>
</center>
</div>
<div class='main'>
<img class='avatar' src='loading.gif'/>
<div class='nickname' style='display:inline;'>Loading your steam profile...</div>
Expand Down
12 changes: 8 additions & 4 deletions steamprofile.php
Expand Up @@ -24,11 +24,15 @@ function dump_array_as_xml($name, $a)


// mainline...
if (isset($_REQUEST['user']))
$user = $_REQUEST['user'];

if (isset($user))
$profile = load_steam_profile($user);
start_session();

if (!isset($_SESSION['steamid']))
print('<profile><steamid>0</steamid></profile>');
exit(0);
}

$profile = load_steam_profile($_SESSION['steamid']);

if ($profile == NULL)
{
Expand Down
11 changes: 11 additions & 0 deletions style.css
Expand Up @@ -68,3 +68,14 @@ td.gamecell {
vertical-align: middle;
}

div.loginpopover {
position: absolute;
left: 10%;
top: 10%;
width: 80%;
height: 80%;
background-color: #ff0000;
color: inherit;
visibility: hidden;
}

0 comments on commit 8cce2ef

Please sign in to comment.