WebFinger support!

This commit is contained in:
Christian Weiske 2012-02-15 08:57:02 +01:00
parent e1655f0e22
commit 3acd0e8db4
5 changed files with 49 additions and 4 deletions

View File

@ -105,6 +105,10 @@
channel="pear.php.net"
minimum_version="0.4.0"
/>
<package name="Net_WebFinger"
channel="pear.php.net"
minimum_version="0.2.0"
/>
<!-- unit tests: -->
<package name="HTML_Request2"
channel="pear.php.net"

View File

@ -18,10 +18,14 @@ if (!$userservice->isSessionStable()) {
<div><input type="hidden" name="query" value="<?php echo $querystring; ?>" /></div>
<table>
<tr>
<th align="left"><label for="openid"><?php echo T_('OpenId'); ?></label></th>
<th align="left"><label for="openid"><?php echo T_('E-Mail or OpenID'); ?></label></th>
<td><input type="text" id="openid" name="openid_identifier" size="20" /></td>
<td></td>
</tr>
<tr>
<td></td>
<td colspan="2" class="login-or">or</td>
</tr>
<tr>
<th align="left"><label for="username"><?php echo T_('Username'); ?></label></th>
<td><input type="text" id="username" name="username" size="20" /></td>

View File

@ -8,7 +8,7 @@ Prerequisites
=============
To run SemanticScuttle, you need:
- PHP5 with filter functions enabled
- PHP5
- A web server, for example Apache

View File

@ -16,6 +16,7 @@ require_once 'SemanticScuttle/Model/OpenId.php';
require_once 'OpenID.php';
require_once 'OpenID/RelyingParty.php';
require_once 'OpenID/Extension/SREG11.php';
require_once 'Net/WebFinger.php';
/**
* SemanticScuttle OpenID verification and management
@ -55,12 +56,46 @@ class SemanticScuttle_Service_OpenId extends SemanticScuttle_DbService
return $instance;
}
/**
* When the user gives an e-mail address instead of an OpenID, we use
* WebFinger to find his OpenID.
*
* @param string $identifier OpenID URL OR e-mail address
*
* @return string Raw/unnormalized OpenID URL.
*
* @throws SemanticScuttle_Exception_User When the user's mail host does not
* support WebFinger
*/
protected function resolveEmailIdentifier($identifier)
{
if (filter_var($identifier, FILTER_VALIDATE_EMAIL) === false) {
//no valid email
return $identifier;
}
require_once 'Net/WebFinger.php';
$wf = new Net_WebFinger();
$react = $wf->finger($identifier);
if ($react->openid === null) {
throw new SemanticScuttle_Exception_User(
'No OpenID found for the given email address ' . $identifier,
20
);
}
return $react->openid;
}
/**
* Part 1 of the OpenID login process: Send user to his identity provider.
*
* If an e-mail address is given, a WebFinger lookup is made to find out the
* user's OpenID.
*
* This method exits the PHP process.
*
* @param string $identifier OpenID URL
* @param string $identifier OpenID URL OR e-mail address
* @param string $returnUrl URL the identity provider shall send the user
* back to
*
@ -70,6 +105,8 @@ class SemanticScuttle_Service_OpenId extends SemanticScuttle_DbService
*/
public function sendIdRequest($identifier, $returnUrl)
{
$identifier = $this->resolveEmailIdentifier($identifier);
//send request to ID provider
try {
$identifier = OpenID::normalizeIdentifier($identifier);

View File

@ -44,7 +44,7 @@ if ($method == 'openidreturn'
&& isset($_POST['openid_identifier']) && $_POST['openid_identifier'] != ''
)
) {
$oids = SemanticScuttle_Service_Factory::get('OpenID');
$oids = SemanticScuttle_Service_Factory::get('OpenId');
$returnUrl = addProtocolToUrl(createURL('login', 'openidreturn'));
try {
if ($method == 'openidreturn') {