Skip to content
Snippets Groups Projects
Commit 34d67462 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

Improvements to OAuth proof of concept code...

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1496 44740490-163a-0410-bde0-09ae8108e29a
parent 9ff0debb
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,13 @@ $requestToken = $consumer->getRequestToken($baseurl . '/module.php/oauth/request
echo "Got a request token from the OAuth service provider [" . $requestToken->key . "] with the secret [" . $requestToken->secret . "]\n";
// Authorize the request token
$consumer->getAuthorizeRequest($baseurl . '/module.php/oauth/authorize.php', $requestToken);
$url = $consumer->getAuthorizeRequest($baseurl . '/module.php/oauth/authorize.php', $requestToken, FALSE);
echo('Go to this URL to authenticate/authorize the request: ' . $url . "\n");
system('open ' . $url);
echo('Waiting 15 seconds for you to complete the authorization...' . "\n");
sleep(15);
// Replace the request token with an access token
$accessToken = $consumer->getAccessToken( $baseurl . '/module.php/oauth/accessToken.php', $requestToken);
......
......@@ -19,13 +19,17 @@ class sspmod_oauth_Consumer {
$this->signer = new OAuthSignatureMethod_HMAC_SHA1();
}
// Used only to load the libextinc library early.
public static function dummy() {}
public function getRequestToken($url) {
$req_req = OAuthRequest::from_consumer_and_token($this->consumer, NULL, "GET", $url, NULL);
$req_req->sign_request($this->signer, $this->consumer, NULL);
echo "Requesting a request token\n";
// echo 'go to url: ' . $req_req->to_url() . "\n"; exit;
$response_req = file_get_contents($req_req->to_url());
if ($response_req === FALSE) {
throw new Exception('Error contacting request_token endpoint on the OAuth Provider');
}
parse_str($response_req, $responseParsed);
......@@ -38,15 +42,16 @@ class sspmod_oauth_Consumer {
return new OAuthToken($requestToken, $requestTokenSecret);
}
public function getAuthorizeRequest($url, $requestToken) {
public function getAuthorizeRequest($url, $requestToken, $redirect = TRUE, $callback = NULL) {
$authorizeURL = $url . '?oauth_token=' . $requestToken->key;
echo "Please go to this URL to authorize access: " . $authorizeURL . "\n";
system("open " . $authorizeURL);
echo "Waiting 15 seconds for you to authenticate. Usually you should let the user enter return or click a continue button.\n";
sleep(15);
if ($callback) {
$authorizeURL .= '&oauth_callback=' . urlencode($callback);
}
if ($redirect) {
SimpleSAML_Utilities::redirect($authorizeURL);
exit;
}
return $authorizeURL;
}
public function getAccessToken($url, $requestToken) {
......@@ -55,6 +60,10 @@ class sspmod_oauth_Consumer {
$acc_req->sign_request($this->signer, $this->consumer, $requestToken);
$response_acc = file_get_contents($acc_req->to_url());
if ($response_acc === FALSE) {
throw new Exception('Error contacting request_token endpoint on the OAuth Provider');
}
parse_str($response_acc, $accessResponseParsed);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment