Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 4: Replace User with Events: AuthRequest, AuthResult.
And broadened "basic" example
- Loading branch information
Showing
15 changed files
with
269 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Goodbye, fair user. <a href="./">Access protected resource</a> | ||
Goodbye, fair user. <a href="./">Come back</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
// the "SP" | ||
require '_inc.php'; | ||
$sp = new Shibalike\SP(getStateManager(), getConfig()); | ||
$sp->requireValidUser(); | ||
|
||
|
||
|
||
// your app's shibboleth auth module here | ||
|
||
$username = $_SERVER['REMOTE_USER']; | ||
|
||
|
||
// the "application" | ||
|
||
header('Content-Type: text/html;charset=utf-8'); | ||
|
||
echo "<h1>Hello, " . htmlspecialchars($_SERVER['displayname'], ENT_QUOTES, 'UTF-8') . "!</h1>"; | ||
|
||
echo "<p>This is a protected resource.</p>"; | ||
|
||
echo "<p><a href='idp.php?logout'>Sign out</a></p>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
// the "SP" | ||
require '_inc.php'; | ||
$sp = new Shibalike\SP(getStateManager(), getConfig()); | ||
|
||
$from = $_SERVER['HTTP_REFERER']; | ||
|
||
$sp->makeAuthRequest($_SERVER['HTTP_REFERER']); | ||
$sp->redirect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Shibalike; | ||
|
||
use Shibalike\Event; | ||
|
||
class AuthRequest extends Event { | ||
|
||
public function __construct($returnUrl = null) | ||
{ | ||
$this->_returnUrl = $returnUrl; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getReturnUrl() | ||
{ | ||
return $this->_returnUrl; | ||
} | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $_returnUrl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Shibalike; | ||
|
||
use Shibalike\Event; | ||
|
||
class AuthResult extends Event { | ||
|
||
/** | ||
* @param string $username | ||
* @param array $attrs | ||
*/ | ||
public function __construct($username, array $attrs) | ||
{ | ||
if (!is_string($username) || $username === '') { | ||
throw new \Exception("username must be a string."); | ||
} | ||
if (empty($attrs)) { | ||
throw new \Exception("attrs must contain at least one attribute"); | ||
} | ||
$this->_username = $username; | ||
$this->_attrs = $attrs; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @param int $ttl | ||
* @return bool | ||
*/ | ||
public function isFresh($ttl) | ||
{ | ||
return ($this->_time + $ttl) > time(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getUsername() | ||
{ | ||
return $this->_username; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getAttrs() | ||
{ | ||
return $this->_attrs; | ||
} | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $_username; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $_attrs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Shibalike; | ||
|
||
use Shibalike\Junction; | ||
|
||
class Event { | ||
|
||
/** | ||
* @param string $name | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->_url = Junction::getCurrentUrl(); | ||
$this->_time = microtime(true); | ||
} | ||
|
||
public function getType() | ||
{ | ||
return get_class($this); | ||
} | ||
|
||
public function getTime() | ||
{ | ||
return $this->_time; | ||
} | ||
|
||
public function getUrl() | ||
{ | ||
return $this->_url; | ||
} | ||
|
||
/** | ||
* @var float | ||
*/ | ||
protected $_time; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $_url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.