Skip to content
This repository
Browse code

1. Remove old local server auth file.

  • Loading branch information...
commit c73b32cdb0cdce8df64c549de3ca6354ad8436bc 1 parent 007b7b5
Patrick Wang, 王致凱 authored April 14, 2012
83  fb_oauth_client.js
... ...
@@ -1,83 +0,0 @@
1  
-var http = require('http');
2  
-var url = require('url');
3  
-var CONFIG = require('./config.js').app_config();
4  
-
5  
-var success_cb;
6  
-var failure_cb;
7  
-
8  
-var httpServer = http.createServer(
9  
-  function(request, response) {
10  
-    var req_info = url.parse(request.url, true);
11  
-    var query = req_info.query;
12  
-
13  
-    if (req_info.pathname == CONFIG['fb_authclient_pathname']) {
14  
-      // First connention, write client page to user's browser.
15  
-      require('fs').readFile(
16  
-        CONFIG['fb_authclient_servpath'],
17  
-        function(err, data) {
18  
-          response.statusCode = 200;
19  
-          response.write(data);
20  
-          response.end();
21  
-        }
22  
-      );
23  
-    } else if (query.hasOwnProperty('access_token')
24  
-               && query.hasOwnProperty('expires_in')) {
25  
-      // Client returns data to us.
26  
-      // *** HERE WE GOT ACCESS TOKEN ***
27  
-      response.end();
28  
-      httpServer.close();
29  
-
30  
-      success_cb(query['access_token'], query['expires_in']);
31  
-    } else if (req_info.pathname == "/") {
32  
-      // Root, redirect to auth_page.
33  
-      response.statusCode = 301;
34  
-      response.setHeader('Location',
35  
-                         CONFIG['fb_authclient_pathname']
36  
-                         + "#client_id=" + CONFIG['fb_client_id']
37  
-                         + "&scope=" + CONFIG['fb_auth_scope'].join(','));
38  
-      response.end();
39  
-    } else {
40  
-      // Error, return 404
41  
-      response.statusCode = 404;
42  
-      response.end();
43  
-    }
44  
-  }
45  
-);
46  
-
47  
-var getTokenWithUsersHelp = function(success_callback,
48  
-                                     failure_callback) {
49  
-  success_cb = success_callback;
50  
-  failure_cb = failure_callback;
51  
-
52  
-  httpServer.listen(40680);
53  
-
54  
-  // Inform user to open browser.
55  
-  console.log("Use browser to open: ");
56  
-  console.log("  http://localhost:40680/");
57  
-}
58  
-
59  
-exports.getAuthToken = function(success_callback,
60  
-                                failure_callback) {
61  
-  var USER_CONFIG = require('./config.js').user_config();
62  
-
63  
-  if (USER_CONFIG.hasOwnProperty('fb_auth_token')
64  
-      && USER_CONFIG['fb_auth_token_expire'] > Date.now()/1000) {
65  
-    // Success callback
66  
-    success_callback(USER_CONFIG['fb_auth_token'],
67  
-                     USER_CONFIG['fb_auth_token_expire']);
68  
-  } else {
69  
-    getTokenWithUsersHelp(
70  
-      function(access_token, expires_in) { // When success.
71  
-
72  
-        // Record to user config.
73  
-        USER_CONFIG['fb_auth_token'] = access_token;
74  
-        USER_CONFIG['fb_auth_token_expire'] = 
75  
-          parseInt(Date.now()/1000) + parseInt(expires_in);
76  
-
77  
-        // Success callback
78  
-        success_callback(USER_CONFIG['fb_auth_token'],
79  
-                         USER_CONFIG['fb_auth_token_expire']);
80  
-      },
81  
-      failure_callback);
82  
-  }
83  
-};
39  oauth_page.html
... ...
@@ -1,39 +0,0 @@
1  
-<html>
2  
-<script language="javascript">
3  
-  
4  
-var hashParams = function() {
5  
-  if (location.href.search('#') < 0) return {};
6  
-  
7  
-  var hash_str = location.href.substr(location.href.search('#') + 1);
8  
-  var lines = hash_str.split('&');
9  
-  var result = {};
10  
-  for (key in lines) {
11  
-    var v = lines[key].split('=');
12  
-    var key = decodeURIComponent(v[0]);
13  
-    var val = decodeURIComponent(v[1]);
14  
-    result[key] = val;
15  
-  }
16  
-  return result;
17  
-};
18  
-
19  
-var run = function() {
20  
-  var params = hashParams();
21  
-  if (params.hasOwnProperty('access_token')) {
22  
-    // Got token
23  
-    location.href = '/'
24  
-      + '?access_token=' + params.access_token
25  
-      + '&expires_in=' + params.expires_in;
26  
-  } else {
27  
-    // Not have the token.
28  
-    location.href = 'https://www.facebook.com/dialog/oauth'
29  
-      + '?client_id=' + params.client_id
30  
-      + '&redirect_uri=' + encodeURIComponent(location.href.split('#', 1)[0])
31  
-      + '&scope=' + params.scope
32  
-      + '&response_type=token'
33  
-  }
34  
-};
35  
-
36  
-run();
37  
-
38  
-</script>
39  
-</html>
51  oauth_server.js
... ...
@@ -1,51 +0,0 @@
1  
-var util = require("util");
2  
-var http = require("http");
3  
-var url = require("url");
4  
-
5  
-var CONFIG = {
6  
-  'fb_app_id'     : '370477596318204',
7  
-  'fb_app_secret' : '',
8  
-  'fb_auth_scope' : '',
9  
-  'fb_oauth_server_port' : 40680
10  
-};
11  
-
12  
-function handle_root(request, response) {
13  
-  // https://www.facebook.com/dialog/oauth?
14  
-  //     client_id=YOUR_APP_ID
15  
-  //    &redirect_uri=YOUR_REDIRECT_URI
16  
-  //    &scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES
17  
-  //    &state=SOME_ARBITRARY_BUT_UNIQUE_STRING
18  
-  var req_info = url.parse(request.url, true); // Get user query
19  
-  var q = req_info.query;
20  
-  if (q.hasOwnProperty('code')) {
21  
-    // We got user's auth code, we can use this code to acquire token.
22  
-    var taken = request_token(q['code']);
23  
-
24  
-    response.statusCode = 200;
25  
-    response.write('Code: ' + q.code);
26  
-    response.end();
27  
-  } else {
28  
-    // We haven't yet get the code, so redirect user to facebook's page.
29  
-    response.statusCode = 301;
30  
-    response.setHeader('Location',
31  
-                       'https://www.facebook.com/dialog/oauth'
32  
-                       + '?client_id=' + CONFIG.fb_app_id
33  
-                       + '&redirect_uri=http://' + request.headers.host + '/'
34  
-                       + '&scope=' + CONFIG.fb_auth_scope);
35  
-    response.end();
36  
-  }
37  
-}
38  
-
39  
-http.createServer(function(request, response) {
40  
-  var req_info = url.parse(request.url);
41  
-  if (req_info.pathname != '/') {
42  
-    // Redirect to root
43  
-    response.statusCode = 301;
44  
-    response.setHeader("Location", "/");
45  
-    response.end();
46  
-  } else {
47  
-    console.log(request.headers.host);
48  
-    handle_root(request, response);
49  
-  }
50  
-}).listen(CONFIG.fb_oauth_server_port);
51  
-

0 notes on commit c73b32c

Please sign in to comment.
Something went wrong with that request. Please try again.