Permalink
Browse files

1. Remove old local server auth file.

  • Loading branch information...
1 parent 007b7b5 commit c73b32cdb0cdce8df64c549de3ca6354ad8436bc @kk1fff kk1fff committed Apr 14, 2012
Showing with 0 additions and 173 deletions.
  1. +0 −83 fb_oauth_client.js
  2. +0 −39 oauth_page.html
  3. +0 −51 oauth_server.js
View
@@ -1,83 +0,0 @@
-var http = require('http');
-var url = require('url');
-var CONFIG = require('./config.js').app_config();
-
-var success_cb;
-var failure_cb;
-
-var httpServer = http.createServer(
- function(request, response) {
- var req_info = url.parse(request.url, true);
- var query = req_info.query;
-
- if (req_info.pathname == CONFIG['fb_authclient_pathname']) {
- // First connention, write client page to user's browser.
- require('fs').readFile(
- CONFIG['fb_authclient_servpath'],
- function(err, data) {
- response.statusCode = 200;
- response.write(data);
- response.end();
- }
- );
- } else if (query.hasOwnProperty('access_token')
- && query.hasOwnProperty('expires_in')) {
- // Client returns data to us.
- // *** HERE WE GOT ACCESS TOKEN ***
- response.end();
- httpServer.close();
-
- success_cb(query['access_token'], query['expires_in']);
- } else if (req_info.pathname == "/") {
- // Root, redirect to auth_page.
- response.statusCode = 301;
- response.setHeader('Location',
- CONFIG['fb_authclient_pathname']
- + "#client_id=" + CONFIG['fb_client_id']
- + "&scope=" + CONFIG['fb_auth_scope'].join(','));
- response.end();
- } else {
- // Error, return 404
- response.statusCode = 404;
- response.end();
- }
- }
-);
-
-var getTokenWithUsersHelp = function(success_callback,
- failure_callback) {
- success_cb = success_callback;
- failure_cb = failure_callback;
-
- httpServer.listen(40680);
-
- // Inform user to open browser.
- console.log("Use browser to open: ");
- console.log(" http://localhost:40680/");
-}
-
-exports.getAuthToken = function(success_callback,
- failure_callback) {
- var USER_CONFIG = require('./config.js').user_config();
-
- if (USER_CONFIG.hasOwnProperty('fb_auth_token')
- && USER_CONFIG['fb_auth_token_expire'] > Date.now()/1000) {
- // Success callback
- success_callback(USER_CONFIG['fb_auth_token'],
- USER_CONFIG['fb_auth_token_expire']);
- } else {
- getTokenWithUsersHelp(
- function(access_token, expires_in) { // When success.
-
- // Record to user config.
- USER_CONFIG['fb_auth_token'] = access_token;
- USER_CONFIG['fb_auth_token_expire'] =
- parseInt(Date.now()/1000) + parseInt(expires_in);
-
- // Success callback
- success_callback(USER_CONFIG['fb_auth_token'],
- USER_CONFIG['fb_auth_token_expire']);
- },
- failure_callback);
- }
-};
View
@@ -1,39 +0,0 @@
-<html>
-<script language="javascript">
-
-var hashParams = function() {
- if (location.href.search('#') < 0) return {};
-
- var hash_str = location.href.substr(location.href.search('#') + 1);
- var lines = hash_str.split('&');
- var result = {};
- for (key in lines) {
- var v = lines[key].split('=');
- var key = decodeURIComponent(v[0]);
- var val = decodeURIComponent(v[1]);
- result[key] = val;
- }
- return result;
-};
-
-var run = function() {
- var params = hashParams();
- if (params.hasOwnProperty('access_token')) {
- // Got token
- location.href = '/'
- + '?access_token=' + params.access_token
- + '&expires_in=' + params.expires_in;
- } else {
- // Not have the token.
- location.href = 'https://www.facebook.com/dialog/oauth'
- + '?client_id=' + params.client_id
- + '&redirect_uri=' + encodeURIComponent(location.href.split('#', 1)[0])
- + '&scope=' + params.scope
- + '&response_type=token'
- }
-};
-
-run();
-
-</script>
-</html>
View
@@ -1,51 +0,0 @@
-var util = require("util");
-var http = require("http");
-var url = require("url");
-
-var CONFIG = {
- 'fb_app_id' : '370477596318204',
- 'fb_app_secret' : '',
- 'fb_auth_scope' : '',
- 'fb_oauth_server_port' : 40680
-};
-
-function handle_root(request, response) {
- // https://www.facebook.com/dialog/oauth?
- // client_id=YOUR_APP_ID
- // &redirect_uri=YOUR_REDIRECT_URI
- // &scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES
- // &state=SOME_ARBITRARY_BUT_UNIQUE_STRING
- var req_info = url.parse(request.url, true); // Get user query
- var q = req_info.query;
- if (q.hasOwnProperty('code')) {
- // We got user's auth code, we can use this code to acquire token.
- var taken = request_token(q['code']);
-
- response.statusCode = 200;
- response.write('Code: ' + q.code);
- response.end();
- } else {
- // We haven't yet get the code, so redirect user to facebook's page.
- response.statusCode = 301;
- response.setHeader('Location',
- 'https://www.facebook.com/dialog/oauth'
- + '?client_id=' + CONFIG.fb_app_id
- + '&redirect_uri=http://' + request.headers.host + '/'
- + '&scope=' + CONFIG.fb_auth_scope);
- response.end();
- }
-}
-
-http.createServer(function(request, response) {
- var req_info = url.parse(request.url);
- if (req_info.pathname != '/') {
- // Redirect to root
- response.statusCode = 301;
- response.setHeader("Location", "/");
- response.end();
- } else {
- console.log(request.headers.host);
- handle_root(request, response);
- }
-}).listen(CONFIG.fb_oauth_server_port);
-

0 comments on commit c73b32c

Please sign in to comment.