Esempio n. 1
0
File: ID.php Progetto: cs50/php
 /**
  * Authenticates user via CS50 ID. If user is returning from CS50 ID,
  * returns associative array of user's claims, else redirects to CS50 ID
  * for authentication.
  *
  * @param string client_id
  * @param string client_secret
  * @param string scope
  *
  * @return array claims
  */
 public static function authenticate($client_id, $client_secret, $scope = "openid profile")
 {
     // validate scope
     // https://tools.ietf.org/html/rfc6749#appendix-A.4
     if (!preg_match("/^[\\x{21}\\x{23}-\\x{5B}\\x{5D}-\\x{7E}]([ \\x{21}\\x{23}-\\x{5B}\\x{5D}-\\x{7E}])*\$/", $scope)) {
         trigger_error("invalid scope", E_USER_ERROR);
     }
     // redirection URI
     try {
         // sans username and password (and fragment)
         $uri = \League\Uri\Schemes\Http::createFromServer($_SERVER)->withUserInfo("");
         // sans code and state (which are reserved by OAuth2)
         $modifier = new \League\Uri\Modifiers\RemoveQueryKeys(["code", "state"]);
         $redirect_uri = $modifier->__invoke($uri)->__toString();
     } catch (\Exception $e) {
         trigger_error("unable to infer redirect_uri", E_USER_ERROR);
     }
     // configure client
     $id = new ID($client_id, $client_secret, $redirect_uri, $scope);
     // if user is returning from CS50 ID, return claims
     if (isset($_GET["code"], $_GET["state"])) {
         return $id->getUser();
     }
     // redirect to CS50 ID
     header("Location: " . $id->getLoginUrl());
     exit;
 }
Esempio n. 2
0
 public function __construct($id = '')
 {
     if ('' == $id) {
         $id = ID::newID();
     }
     $this->id = $id;
 }
Esempio n. 3
0
File: IDTest.php Progetto: slim/heer
 function setUp()
 {
     require_once '../lib/id.php';
     ID::set_seed('test');
     $this->id = new ID();
     $this->customId = new ID();
     $this->customId->value = 555 . ':' . md5('555test');
 }
Esempio n. 4
0
File: ID.php Progetto: tarcisio/svg
 public static function newID()
 {
     $id = ID::$ids[0];
     while (in_array($id, ID::$ids)) {
         $id .= ID::getRandChar();
     }
     ID::$ids[] = $id;
     return $id;
 }
Esempio n. 5
0
File: index.php Progetto: slim/heer
<?php

require '../../../lib/link.php';
require '../../../lib/id.php';
require '../../../lib/vote.php';
Link::set_db('sqlite:../../../heer.db');
Vote::set_db('sqlite:../../../heer.db');
ID::set_seed(file_get_contents('../../../seed'));
$url = $_GET['u'];
$title = $_GET['t'];
$bookmarklet = new ID($_GET['i']);
$vote = new Vote($url, $bookmarklet);
if ($_GET['n']) {
    $vote->note = $_GET['n'];
}
$link = new Link($url, $title);
if ($bookmarklet->isAuthentic() && $vote->save()) {
    $link->save();
}
header("Location: {$url}");
Esempio n. 6
0
File: id.php Progetto: slim/heer
 static function set_seed($seed)
 {
     ID::$seed = $seed;
 }
Esempio n. 7
0
File: index.php Progetto: slim/heer
<?php

require "../../lib/id.php";
ID::set_seed(file_get_contents('../../seed'));
$submitUrl = $_GET['u'];
$bookmarkletTitle = $_GET['t'] ? $_GET['t'] : "heer";
$bookmarkletID = new ID();
?>
<a href="javascript:location.href='<?php 
echo $submitUrl;
?>
?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title)+'&i=<?php 
echo $bookmarkletID;
?>
'"><?php 
echo $bookmarkletTitle;
?>
</a>