Permalink
Browse files

Uploading OAuth Example

  • Loading branch information...
1 parent fc76393 commit 9d16f4edc7544357d7988cf24a639069c0e68f43 @TaltonFiggins TaltonFiggins committed Aug 7, 2012
Showing with 60 additions and 0 deletions.
  1. +10 −0 php/oauth/README.markdown
  2. +42 −0 php/oauth/oauth-callback.php
  3. +8 −0 php/oauth/oauth-test.php
View
@@ -0,0 +1,10 @@
+# DISQUS OAuth Test
+
+This recipe will show you a method of setting up a simple OAuth session and recieving the Access Token necessary to make API requests requiring authentication.
+
+How it Works:
+* oauth-test.php provides a link which will pass the string necessary to pull up an authentication page within DISQUS
+* After authenticating you'll be sent to your redirect URL (example.com/oauth-callback.php)
+* You'll then be provided with the access token necessary to use API methods that require authentication
+
+Additional information on DISQUS authentication can be found here: http://disqus.com/api/docs/auth/
@@ -0,0 +1,42 @@
+<?php
+
+ $PUBLIC_KEY = "PUT_YOUR_PUBLIC_KEY_HERE";
+ $SECRET_KEY = "PUT_YOUR_SECRET_KEY_HERE";
+
+ // Get the code for request access
+ $CODE = $_GET['code'];
+
+// Request the access token
+extract($_POST);
+
+$authorize = "authorization_code";
+$redirect = "http://www.example.com/results-page";
+
+$url = 'https://disqus.com/api/oauth/2.0/access_token/?';
+$fields = array(
+ 'grant_type'=>urlencode($authorize),
+ 'client_id'=>urlencode($PUBLIC_KEY),
+ 'client_secret'=>urlencode($SECRET_KEY),
+ 'redirect_uri'=>urlencode($redirect),
+ 'code'=>urlencode($CODE)
+);
+
+//url-ify the data for the POST
+foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
+rtrim($fields_string, "&");
+
+//open connection
+$ch = curl_init();
+
+//set the url, number of POST vars, POST data
+curl_setopt($ch,CURLOPT_URL,$url);
+curl_setopt($ch,CURLOPT_POST,count($fields));
+curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
+
+//execute post
+$result = curl_exec($ch);
+
+//close connection
+curl_close($ch);
+
+?>
View
@@ -0,0 +1,8 @@
+<?php
+
+// This should redirect to the second OAuth file provided
+echo "<a href='https://disqus.com/api/oauth/2.0/authorize/?client_id=YOUR_PUBLIC_KEY&scope=read,write&response_type=code&redirect_uri=http://www.example.com/oauth-callback.php'>OAuth</a>";
+
+ ?>
+
+

0 comments on commit 9d16f4e

Please sign in to comment.