upgrade
This commit is contained in:
74
plugin/ims_lti/vendor/oauth1/example/SimpleOAuthDataStore.php
vendored
Normal file
74
plugin/ims_lti/vendor/oauth1/example/SimpleOAuthDataStore.php
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/* A very naive dbm-based oauth storage
|
||||
*
|
||||
* NOTE: This is for reference ONLY,
|
||||
* and contains, amongst others, a hole
|
||||
* where you can get the token secret
|
||||
* easily..
|
||||
*/
|
||||
class SimpleOAuthDataStore extends OAuthDataStore {/*{{{*/
|
||||
private $dbh;
|
||||
|
||||
function __construct($path = "oauth.gdbm") {/*{{{*/
|
||||
$this->dbh = dba_popen($path, 'c', 'gdbm');
|
||||
}/*}}}*/
|
||||
|
||||
function __destruct() {/*{{{*/
|
||||
dba_close($this->dbh);
|
||||
}/*}}}*/
|
||||
|
||||
function lookup_consumer($consumer_key) {/*{{{*/
|
||||
$rv = dba_fetch("consumer_$consumer_key", $this->dbh);
|
||||
if ($rv === FALSE) {
|
||||
return NULL;
|
||||
}
|
||||
$obj = unserialize($rv);
|
||||
if (!($obj instanceof OAuthConsumer)) {
|
||||
return NULL;
|
||||
}
|
||||
return $obj;
|
||||
}/*}}}*/
|
||||
|
||||
function lookup_token($consumer, $token_type, $token) {/*{{{*/
|
||||
$rv = dba_fetch("${token_type}_${token}", $this->dbh);
|
||||
if ($rv === FALSE) {
|
||||
return NULL;
|
||||
}
|
||||
$obj = unserialize($rv);
|
||||
if (!($obj instanceof OAuthToken)) {
|
||||
return NULL;
|
||||
}
|
||||
return $obj;
|
||||
}/*}}}*/
|
||||
|
||||
function lookup_nonce($consumer, $token, $nonce, $timestamp) {/*{{{*/
|
||||
if (dba_exists("nonce_$nonce", $this->dbh)) {
|
||||
return TRUE;
|
||||
} else {
|
||||
dba_insert("nonce_$nonce", "1", $this->dbh);
|
||||
return FALSE;
|
||||
}
|
||||
}/*}}}*/
|
||||
|
||||
function new_token($consumer, $type="request") {/*{{{*/
|
||||
$key = md5(time());
|
||||
$secret = time() + time();
|
||||
$token = new OAuthToken($key, md5(md5($secret)));
|
||||
if (!dba_insert("${type}_$key", serialize($token), $this->dbh)) {
|
||||
throw new OAuthException("doooom!");
|
||||
}
|
||||
return $token;
|
||||
}/*}}}*/
|
||||
|
||||
function new_request_token($consumer) {/*{{{*/
|
||||
return $this->new_token($consumer, "request");
|
||||
}/*}}}*/
|
||||
|
||||
function new_access_token($token, $consumer) {/*{{{*/
|
||||
|
||||
$token = $this->new_token($consumer, 'access');
|
||||
dba_delete("request_" . $token->key, $this->dbh);
|
||||
return $token;
|
||||
}/*}}}*/
|
||||
}/*}}}*/
|
||||
14
plugin/ims_lti/vendor/oauth1/example/access_token.php
vendored
Normal file
14
plugin/ims_lti/vendor/oauth1/example/access_token.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
require_once("common.inc.php");
|
||||
|
||||
try {
|
||||
$req = OAuthRequest::from_request();
|
||||
$token = $test_server->fetch_access_token($req);
|
||||
print $token;
|
||||
} catch (OAuthException $e) {
|
||||
print($e->getMessage() . "\n<hr />\n");
|
||||
print_r($req);
|
||||
die();
|
||||
}
|
||||
|
||||
?>
|
||||
133
plugin/ims_lti/vendor/oauth1/example/client.php
vendored
Normal file
133
plugin/ims_lti/vendor/oauth1/example/client.php
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
require_once("common.inc.php");
|
||||
|
||||
$key = @$_REQUEST['key'];
|
||||
$secret = @$_REQUEST['secret'];
|
||||
$token = @$_REQUEST['token'];
|
||||
$token_secret = @$_REQUEST['token_secret'];
|
||||
$endpoint = @$_REQUEST['endpoint'];
|
||||
$action = @$_REQUEST['action'];
|
||||
$dump_request = @$_REQUEST['dump_request'];
|
||||
$user_sig_method = @$_REQUEST['sig_method'];
|
||||
$sig_method = $hmac_method;
|
||||
if ($user_sig_method) {
|
||||
$sig_method = $sig_methods[$user_sig_method];
|
||||
}
|
||||
|
||||
$test_consumer = new OAuthConsumer($key, $secret, NULL);
|
||||
|
||||
$test_token = NULL;
|
||||
if ($token) {
|
||||
$test_token = new OAuthConsumer($token, $token_secret);
|
||||
}
|
||||
|
||||
|
||||
if ($action == "request_token") {
|
||||
$parsed = parse_url($endpoint);
|
||||
$params = array();
|
||||
parse_str($parsed['query'], $params);
|
||||
|
||||
$req_req = OAuthRequest::from_consumer_and_token($test_consumer, NULL, "GET", $endpoint, $params);
|
||||
$req_req->sign_request($sig_method, $test_consumer, NULL);
|
||||
if ($dump_request) {
|
||||
Header('Content-type: text/plain');
|
||||
print "request url: " . $req_req->to_url(). "\n";
|
||||
print_r($req_req);
|
||||
exit;
|
||||
}
|
||||
Header("Location: $req_req");
|
||||
}
|
||||
else if ($action == "authorize") {
|
||||
$callback_url = "$base_url/client.php?key=$key&secret=$secret&token=$token&token_secret=$token_secret&endpoint=" . urlencode($endpoint);
|
||||
$auth_url = $endpoint . "?oauth_token=$token&oauth_callback=".urlencode($callback_url);
|
||||
if ($dump_request) {
|
||||
Header('Content-type: text/plain');
|
||||
print("auth_url: " . $auth_url);
|
||||
exit;
|
||||
}
|
||||
Header("Location: $auth_url");
|
||||
}
|
||||
else if ($action == "access_token") {
|
||||
$parsed = parse_url($endpoint);
|
||||
$params = array();
|
||||
parse_str($parsed['query'], $params);
|
||||
|
||||
$acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, "GET", $endpoint, $params);
|
||||
$acc_req->sign_request($sig_method, $test_consumer, $test_token);
|
||||
if ($dump_request) {
|
||||
Header('Content-type: text/plain');
|
||||
print "request url: " . $acc_req->to_url() . "\n";
|
||||
print_r($acc_req);
|
||||
exit;
|
||||
}
|
||||
Header("Location: $acc_req");
|
||||
}
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>OAuth Test Client</title>
|
||||
</head>
|
||||
<body>
|
||||
<div><a href="index.php">server</a> | <a href="client.php">client</a></div>
|
||||
<h1>OAuth Test Client</h1>
|
||||
<h2>Instructions for Use</h2>
|
||||
<p>This is a test client that will let you test your OAuth server code. Enter the appropriate information below to test.</p>
|
||||
<p>Note: we don't store any of the information you type in.</p>
|
||||
|
||||
<form method="POST" name="oauth_client">
|
||||
<h3>Choose a Signature Method</h3>
|
||||
<select name="sig_method">
|
||||
<?php
|
||||
foreach ($sig_methods as $name=> $method) {
|
||||
$selected = "";
|
||||
if ($name == $sig_method->get_name()) {
|
||||
$selected = " selected='selected'";
|
||||
}
|
||||
print "<option value='$name'$selected>$name</option>\n";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<h3>Enter The Endpoint to Test</h3>
|
||||
endpoint: <input type="text" name="endpoint" value="<?php echo $endpoint; ?>" size="100"/><br />
|
||||
<small style="color: green">Note: You can include query parameters in there to have them parsed in and signed too</small>
|
||||
<h3>Enter Your Consumer Key / Secret</h3>
|
||||
consumer key: <input type="text" name="key" value="<?php echo $key; ?>" /><br />
|
||||
consumer secret: <input type="text" name="secret" value="<?php echo $secret;?>" /><br />
|
||||
dump request, don't redirect: <input type="checkbox" name="dump_request" value="1" <?php if ($dump_request) echo 'checked="checked"'; ?>/><br />
|
||||
make a token request (don't forget to copy down the values you get)
|
||||
<input type="submit" name="action" value="request_token" />
|
||||
<h3>Enter Your Request Token / Secret</h3>
|
||||
token: <input type="text" name="token" value="<?php echo $token; ?>" /><br />
|
||||
token secret: <input type="text" name="token_secret" value="<?php echo $token_secret; ?>" /><br />
|
||||
<p><strong>Don't forget to update your endpoint to point at the auth or access token url</strong></p>
|
||||
try to authorize this token: <input type="submit" name="action" value="authorize" /><br />
|
||||
try to get an access token: <input type="submit" name="action" value="access_token" /><br />
|
||||
|
||||
<h3>Currently Supported Signature Methods</h3>
|
||||
<p>Current signing method is: <?php echo $sig_method->get_name() ?></p>
|
||||
<ul>
|
||||
<?php
|
||||
foreach ($sig_methods as $key => $method) {
|
||||
|
||||
print "<li>$key";
|
||||
if ($key != $sig_method->get_name()) {
|
||||
print "(<a href='?sig_method=$key'>switch</a>)";
|
||||
}
|
||||
print "</li>\n";
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
if ("RSA-SHA1" == $sig_method->get_name()) {
|
||||
// passing test_server as a dummy referecne
|
||||
print "<pre>" . $sig_method->fetch_private_cert($test_server). "</pre>\n";
|
||||
print "<pre>" . $sig_method->fetch_public_cert($test_server) . "</pre>\n";
|
||||
}
|
||||
?>
|
||||
|
||||
<h3>Further Resources</h3>
|
||||
<p>There is also a <a href="index.php">test server</a> implementation in here.</p>
|
||||
<p>The code running this example can be downloaded from the PHP section of the OAuth google code project: <a href="http://code.google.com/p/oauth/">http://code.google.com/p/oauth/</a>
|
||||
</body>
|
||||
26
plugin/ims_lti/vendor/oauth1/example/common.inc.php
vendored
Normal file
26
plugin/ims_lti/vendor/oauth1/example/common.inc.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
require_once("../init.php");
|
||||
require_once("../code/OAuth_TestServer.php");
|
||||
|
||||
/*
|
||||
* Config Section
|
||||
*/
|
||||
$domain = $_SERVER['HTTP_HOST'];
|
||||
$base = "/oauth/example";
|
||||
$base_url = "http://$domain$base";
|
||||
|
||||
/**
|
||||
* Some default objects
|
||||
*/
|
||||
|
||||
$test_server = new TestOAuthServer(new MockOAuthDataStore());
|
||||
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
|
||||
$plaintext_method = new OAuthSignatureMethod_PLAINTEXT();
|
||||
$rsa_method = new TestOAuthSignatureMethod_RSA_SHA1();
|
||||
|
||||
$test_server->add_signature_method($hmac_method);
|
||||
$test_server->add_signature_method($plaintext_method);
|
||||
$test_server->add_signature_method($rsa_method);
|
||||
|
||||
$sig_methods = $test_server->get_signature_methods();
|
||||
?>
|
||||
21
plugin/ims_lti/vendor/oauth1/example/echo_api.php
vendored
Normal file
21
plugin/ims_lti/vendor/oauth1/example/echo_api.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
require_once("common.inc.php");
|
||||
|
||||
try {
|
||||
$req = OAuthRequest::from_request();
|
||||
list($consumer, $token) = $test_server->verify_request($req);
|
||||
|
||||
// lsit back the non-OAuth params
|
||||
$total = array();
|
||||
foreach($req->get_parameters() as $k => $v) {
|
||||
if (substr($k, 0, 5) == "oauth") continue;
|
||||
$total[] = urlencode($k) . "=" . urlencode($v);
|
||||
}
|
||||
print implode("&", $total);
|
||||
} catch (OAuthException $e) {
|
||||
print($e->getMessage() . "\n<hr />\n");
|
||||
print_r($req);
|
||||
die();
|
||||
}
|
||||
|
||||
?>
|
||||
108
plugin/ims_lti/vendor/oauth1/example/index.php
vendored
Normal file
108
plugin/ims_lti/vendor/oauth1/example/index.php
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
require_once("common.inc.php");
|
||||
|
||||
|
||||
$test_consumer = new OAuthConsumer("key", "secret", NULL);
|
||||
$req_token = new OAuthConsumer("requestkey", "requestsecret", 1);
|
||||
$acc_token = new OAuthConsumer("accesskey", "accesssecret", 1);
|
||||
|
||||
$sig_method = $hmac_method;
|
||||
$user_sig_method = @$_GET['sig_method'];
|
||||
if ($user_sig_method) {
|
||||
$sig_method = $sig_methods[$user_sig_method];
|
||||
}
|
||||
|
||||
$req_req = OAuthRequest::from_consumer_and_token($test_consumer, NULL, "GET", $base_url . "/request_token.php");
|
||||
$req_req->sign_request($sig_method, $test_consumer, NULL);
|
||||
|
||||
$acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $req_token, "GET", $base_url . "/access_token.php");
|
||||
$acc_req->sign_request($sig_method, $test_consumer, $req_token);
|
||||
|
||||
$echo_req = OAuthRequest::from_consumer_and_token($test_consumer, $acc_token, "GET", $base_url . "/echo_api.php", array("method"=> "foo%20bar", "bar" => "baz"));
|
||||
$echo_req->sign_request($sig_method, $test_consumer, $acc_token);
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>OAuth Test Server</title>
|
||||
</head>
|
||||
<body>
|
||||
<div><a href="index.php">server</a> | <a href="client.php">client</a></div>
|
||||
<h1>OAuth Test Server</h1>
|
||||
<h2>Instructions for Use</h2>
|
||||
<p>This is a test server with a predefined static set of keys and tokens, you can make your requests using them to test your code (and mine ;)).</p>
|
||||
<h3>Your Consumer Key / Secret</h3>
|
||||
<ul>
|
||||
<li>consumer key: <code><strong>key</strong></code></li>
|
||||
<li>consumer secret: <code><strong>secret</strong></code></li>
|
||||
</ul>
|
||||
<p>Use this key and secret for all your requests.</p>
|
||||
<h3>Getting a Request Token</h3>
|
||||
|
||||
<ul>
|
||||
<li>request token endpoint: <code><strong><?php echo $base_url . "/request_token.php"; ?></strong></code></li>
|
||||
</ul>
|
||||
|
||||
<p>A successful request will return the following:</p>
|
||||
<p><code>oauth_token=requestkey&oauth_token_secret=requestsecret</code></p>
|
||||
|
||||
<p>An unsuccessful request will attempt to describe what went wrong.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
<a href="<?php echo $req_req; ?>"><?php echo $req_req; ?></a>
|
||||
|
||||
<h3>Getting an Access Token</h3>
|
||||
<p>The Request Token provided above is already authorized, you may use it to request an Access Token right away.</p>
|
||||
|
||||
<ul>
|
||||
<li>access token endpoint: <code><strong><?php echo $base_url . "/access_token.php"; ?></strong></code></li>
|
||||
</ul>
|
||||
|
||||
<p>A successful request will return the following:</p>
|
||||
<p><code>oauth_token=accesskey&oauth_token_secret=accesssecret</code></p>
|
||||
|
||||
<p>An unsuccessful request will attempt to describe what went wrong.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
<a href="<?php echo $acc_req; ?>"><?php echo $acc_req; ?></a>
|
||||
|
||||
<h3>Making Authenticated Calls</h3>
|
||||
<p>Using your Access Token you can make authenticated calls.</p>
|
||||
|
||||
<ul>
|
||||
<li>api endpoint: <code><strong><?php echo $base_url . "/echo_api.php"; ?></strong></code></li>
|
||||
</ul>
|
||||
<p>
|
||||
A successful request will echo the non-OAuth parameters sent to it, for example:</p>
|
||||
<p><code>method=foo&bar=baz</code></p>
|
||||
<p>An unsuccessful request will attempt to describe what went wrong.</p>
|
||||
|
||||
<h4>Example</h4>
|
||||
<a href="<?php echo $echo_req; ?>"><?php echo $echo_req; ?></a>
|
||||
|
||||
<h3>Currently Supported Signature Methods</h3>
|
||||
<p>Current signing method is: <?php echo $user_sig_method ?></p>
|
||||
<ul>
|
||||
<?php
|
||||
$sig_methods = $test_server->get_signature_methods();
|
||||
foreach ($sig_methods as $key => $method) {
|
||||
print "<li>$key";
|
||||
if ($key != $sig_method->get_name()) {
|
||||
print "(<a href='?sig_method=$key'>switch</a>)";
|
||||
}
|
||||
print "</li>\n";
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
if ("RSA-SHA1" == $sig_method->get_name()) {
|
||||
print "<pre>" . $sig_method->fetch_private_cert($req_req) . "</pre>\n";
|
||||
print "<pre>" . $sig_method->fetch_public_cert($req_req) . "</pre>\n";
|
||||
}
|
||||
?>
|
||||
|
||||
<h3>Further Resources</h3>
|
||||
<p>There is also a <a href="client.php">test client</a> implementation in here.</p>
|
||||
<p>The code running this example can be downloaded from the PHP section of the OAuth google code project: <a href="http://code.google.com/p/oauth/">http://code.google.com/p/oauth/</a>
|
||||
</body>
|
||||
14
plugin/ims_lti/vendor/oauth1/example/request_token.php
vendored
Normal file
14
plugin/ims_lti/vendor/oauth1/example/request_token.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
require_once("common.inc.php");
|
||||
|
||||
try {
|
||||
$req = OAuthRequest::from_request();
|
||||
$token = $test_server->fetch_request_token($req);
|
||||
print $token;
|
||||
} catch (OAuthException $e) {
|
||||
print($e->getMessage() . "\n<hr />\n");
|
||||
print_r($req);
|
||||
die();
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user