Exemple #1
0
 /**
  * Test for SimpleSAML\Utils\Random::generateID().
  *
  * @covers SimpleSAML\Utils\Random::generateID
  */
 public function testGenerateID()
 {
     // check that it always starts with an underscore
     $this->assertStringStartsWith('_', Random::generateID());
     // check the length
     $this->assertEquals(Random::ID_LENGTH, strlen(Random::generateID()));
 }
 private function getId()
 {
     return \SimpleSAML\Utils\Random::generateID();
 }
 public function restoreSecret($clientIdentifier)
 {
     $secret = Random::generateID();
     $this->conn->update($this->getTableName(), ['secret' => $secret], ['id' => $clientIdentifier], ['string']);
 }
Exemple #4
0
 /**
  * Save the given HTTP POST data and the destination where it should be posted to a given session.
  *
  * @param \SimpleSAML_Session $session The session where to temporarily store the data.
  * @param string              $destination The destination URL where the form should be posted.
  * @param array               $data An associative array with the data to be posted to $destination.
  *
  * @return string A random identifier that can be used to retrieve the data from the current session.
  *
  * @author Andjelko Horvat
  * @author Jaime Perez, UNINETT AS <*****@*****.**>
  */
 private static function savePOSTData(\SimpleSAML_Session $session, $destination, $data)
 {
     // generate a random ID to avoid replay attacks
     $id = Random::generateID();
     $postData = array('post' => $data, 'url' => $destination);
     // save the post data to the session, tied to the random ID
     $session->setData('core_postdatalink', $id, $postData);
     return $id;
 }
 *
 * The configuration for this script is stored in config/authmemcookie.php.
 *
 * The file extra/auth_memcookie.conf contains an example of how Auth Memcookie can be configured
 * to use SimpleSAMLphp.
 */
// load SimpleSAMLphp configuration
$ssp_cf = \SimpleSAML_Configuration::getInstance();
// load Auth MemCookie configuration
$amc_cf = AuthMemCookie::getInstance();
$sourceId = $amc_cf->getAuthSource();
$s = new SimpleSAML_Auth_Simple($sourceId);
// check if the user is authorized. We attempt to authenticate the user if not
$s->requireAuth();
// generate session id and save it in a cookie
$sessionID = Utils\Random::generateID();
$cookieName = $amc_cf->getCookieName();
\SimpleSAML\Utils\HTTP::setCookie($cookieName, $sessionID);
// generate the authentication information
$attributes = $s->getAttributes();
$authData = array();
// username
$usernameAttr = $amc_cf->getUsernameAttr();
if (!array_key_exists($usernameAttr, $attributes)) {
    throw new SimpleSAML_Error_Exception("The user doesn't have an attribute named '" . $usernameAttr . "'. This attribute is expected to contain the username.");
}
$authData['UserName'] = $attributes[$usernameAttr];
// groups
$groupsAttr = $amc_cf->getGroupsAttr();
if ($groupsAttr !== null) {
    if (!array_key_exists($groupsAttr, $attributes)) {
/*
 * This file is part of the simplesamlphp-module-oauth2.
 *
 * (c) Sergio Gómez <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use SimpleSAML\Modules\OAuth2\Form\ClientForm;
use SimpleSAML\Modules\OAuth2\Repositories\ClientRepository;
use SimpleSAML\Utils\Auth;
use SimpleSAML\Utils\HTTP;
use SimpleSAML\Utils\Random;
/* Load simpleSAMLphp, configuration and metadata */
$action = \SimpleSAML\Module::getModuleURL('oauth2/registry.new.php');
$config = SimpleSAML_Configuration::getInstance();
Auth::requireAdmin();
$form = new ClientForm('client');
$form->setAction($action);
if ($form->isSubmitted() && $form->isSuccess()) {
    $client = $form->getValues();
    $client['id'] = Random::generateID();
    $client['secret'] = Random::generateID();
    $clientRepository = new ClientRepository();
    $clientRepository->persistNewClient($client['id'], $client['secret'], $client['name'], $client['description'], $client['redirect_uri']);
    HTTP::redirectTrustedURL('registry.php');
}
$template = new SimpleSAML_XHTML_Template($config, 'oauth2:registry_new');
$template->data['form'] = $form;
$template->show();