Permalink
Browse files

Initial commit of oauth handshake for dropbox.

  • Loading branch information...
1 parent ae53336 commit 31b873937ec473942e0f2765a4029c0e3e2772fb @joemccann committed Dec 23, 2011
View
@@ -5,5 +5,6 @@ logs/*
dump.rdb
public/files/*
config/github.json
+config/dropbox.json
config/server.json
config/redis.conf
View
@@ -9,9 +9,11 @@ var express = require('express')
, cluster = require('cluster')
, path = require('path')
, redis = require('redis')
+ , async = require('async')
, passwordHash = require('password-hash')
, md = require(__dirname + '/utils/md').md
, github = require(__dirname + '/utils/github').github
+ , dbox = require(__dirname + '/utils/dropbox').dropbox
, debug
, redisStore
, redisClient
@@ -68,10 +70,25 @@ app.configure(function(){
app.use(express.static(__dirname + '/public'));
});
-app.dynamicHelpers({
- readme: function(req,res){
- return dillingerReadme.toString()
- }
+app.dynamicHelpers(
+ {
+ readme: function(req,res){
+ return dillingerReadme.toString()
+ }
+ , dropbox: function(req,res){
+
+ if(typeof req.session.dropbox !== 'undefined' && req.session.dropbox.sync){
+ return req.session.dropbox
+ }
+ else{
+ var drop = {
+ sync : null
+ , oauth_token: dbox.getAccessToken()
+ , oauth_callback: dbox.getOauthCallback()
+ }
+ return drop
+ }
+ }
})
@@ -155,6 +172,7 @@ app.get('/', function(req, res, next){
})
+/* Github OAuth */
app.get('/oauth/github', function(req, res, next){
if(!req.query.code) next()
@@ -204,6 +222,57 @@ app.get('/oauth/test/github', function(req, res){
})
+
+function requestDropboxToken(){
+
+ var url = dropbox_api + "oauth/request_token"
+
+ function _tokenHandler(err,resp,data){ }
+
+ // Make a request to dropbox api to get token
+ var iterator = async.iterator([
+ function(){
+ request.post(url, function(err, resp, data){
+ // sample response: oauth_token_secret=b9q1n5il4lcc&oauth_token=mh7an9dkrg59
+
+ var token = data.split('=').pop();
+ console.log(token)
+
+ return data.split('=').pop()
+
+ })
+ }
+ ])
+
+ return iterator()
+
+} // end requestDropboxToken()
+
+
+// requestDropboxToken()
+
+
+app.get('/oauth/dropbox', function(req, res, next){
+
+ // id=409429&oauth_token=15usk7o67ckg644
+
+ if(!req.query.oauth_token) next()
+ else{
+ req.session.dropbox = {}
+
+ req.session.dropbox.sync = true
+ req.session.dropbox.oauth_token = true
+
+ res.redirect('/')
+
+ } // end else
+
+})
+
+
+
+/* Github Actions */
+
app.post('/github/repo/fetch_all', function(req,res){
var github_url = github_api + 'user/repos?access_token=' + req.session.oauth.github
@@ -350,6 +419,8 @@ app.post('/github/repo/fetch_markdown_file', function(req,res){
})
+/* Dillinger Actions */
+
// save a markdown file and send header to download it directly as response
app.post('/factory/fetch_markdown', function(req,res){
@@ -413,7 +484,6 @@ app.post('/factory/fetch_html', function(req,res){
}) // end post
-
// route to handle download of md file
app.get('/files/md/:mdid', function(req, res){
@@ -456,6 +526,8 @@ app.get('/files/html/:html', function(req, res){
})
+
+
// TODO: ADD THESE LATER? Nah, fuck it, Github is good enough.
app.get('/oauth/facebook', function(req,res){
res.send('Not implemented yet.')
@@ -506,7 +578,7 @@ function init(){
if (cluster.isMaster){
// Fork workers.
- for (var i = 0; i < numCPUs; i++) {
+ for (var i = 0; i < (debug ? 1 : numCPUs); i++) {
cluster.fork()
}
View
@@ -10,7 +10,7 @@
"DIST_DIR": "./public/css",
"dillinger": ["./public/css/dillinger.css"]
},
- "DEBUG": false,
+ "DEBUG": true,
"PORT": 80,
"LOCALHOST": false,
"IMAGE_PREFIX_DEBUG": "/img/",
View
@@ -14,6 +14,24 @@ It should look like the following:
To obtain the `client_id` and the `client_secret` you'll need to register your application with Github. Do that here: [Github App]
+
+Dropbox Config
+=========
+
+In order to use the dropbox features associated with Dilinger you need to create a file in this directory called `dropbox.json`.
+
+It should look like the following:
+
+ {
+ "consumer_key": "someRandomString"
+ , "consumer_secret": "someRandomString"
+ , "email": "yourEmailAddressForDropbox"
+ , "password": "yourPasswordForDropbox"
+ }
+
+To obtain the `consumer_key` and the `consumer_secret` you'll need to register your application with Dropbox. Do that here: [Dropbox App]
+
+
Redis Config
=========
@@ -25,4 +43,5 @@ In order to shut down the admin party (meaning everyone has access) with Redis,
Done!
- [Github App]: https://github.com/account/applications/new
+ [Github App]: https://github.com/account/applications/new
+ [Dropbox App]: https://www.dropbox.com/developers/apps
View
@@ -25,5 +25,7 @@
, "asciimo": "0.3.1"
, "gzip": "0.1.0"
, "jsdom": "0.2.9"
+ , "async": ">=0.1.15",
+ , "dropbox": ">=0.3.3"
}
}
@@ -1993,7 +1993,7 @@ footer {
color: #eee;
background-position: 0 -15px;
}
-.btn.github {
+.btn.vendor {
color: #fff;
background-color: #b85c00;
background-repeat: no-repeat;
@@ -2007,7 +2007,7 @@ footer {
border-color: #c60 #c60 #ad5700;
border-color: rgba(0,0,0,0.10) rgba(0,0,0,0.10) rgba(0,0,0,0.00);
}
-.btn.github:hover {
+.btn.vendor:hover {
color: #eee;
background-position: 0 -15px;
}
@@ -2601,13 +2601,18 @@ nav {
.relative {
position: relative;
}
-.github {
+.vendor {
padding-left: 30px;
}
-.icon_octocat {
+.icon_vendor {
position: absolute;
+}
+.icon_vendor.github {
margin: 3px 0 0 6px;
}
+.icon_vendor.dropbox {
+ margin: 6px 0 0 9px;
+}
#theme {
float: right;
margin-right: 235px;
@@ -5,13 +5,18 @@ nav
.relative
position relative
-.github
+.vendor
padding-left 30px
-.icon_octocat
+.icon_vendor
position absolute
+
+.icon_vendor.github
margin 3px 0 0 6px
-
+
+.icon_vendor.dropbox
+ margin 6px 0 0 9px
+
#theme
float right
margin-right 235px
@@ -571,14 +571,14 @@ footer
color #eee
background-position 0 -15px
- &.github
+ &.vendor
color white
c=github
cd=githubDark
gradient-vertical-three-colors(c, c, 25%, darken(cd, 10%)) // Don't use gradientBar() here since it does a three-color gradient
gradientBar( c, cd)
- &.github:hover
+ &.vendor:hover
color #eee
background-position 0 -15px
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,41 @@
+var DropboxClient = require('dropbox').DropboxClient
+ , fs = require('fs')
+
+var config = JSON.parse(fs.readFileSync('./config/dropbox.json'))
+
+function Dropbox(){
+
+ var _dropbox
+ , _access_token = _access_secret = ''
+
+ // Like a constructor
+
+ _dropbox = new DropboxClient(config.consumer_key, config.consumer_secret)
+
+ _dropbox.getAccessToken(config.email, config.password, function(err, token, secret) {
+ if(err) {
+ console.error(err)
+ throw err
+ }else{
+ _access_token = token
+ _access_secret = secret
+ }
+ }) // end getAccessToken
+
+ return {
+
+ getAccessToken: function(){
+ return _access_token
+ },
+ getAccessSecret: function(){
+ return _access_secret
+ },
+ getOauthCallback: function(){
+ return config.oauth_callback
+ }
+
+ } // end API
+
+} // end Dropbox()
+
+exports.dropbox = new Dropbox()
View
@@ -11,9 +11,14 @@
<a href="#" class="btn success" id="export_md">Export Markdown</a> |
<a href="#" class="btn success" id="export_html">Export HTML</a> |
<span class="relative">
- <img src="/img/icon_octocat_20x20.png" class="icon_octocat" alt="Octocat Icon"><% if(!loggedIn){ %>
- <a href="https://github.com/login/oauth/authorize?client_id=<%- github.client_id %>&scope=repo&redirect_uri=<%- github.callback_url %>" id="oauth_github" class="btn github">Sign in With Github</a><% }%><% if(loggedIn){ %>
- <a href="#" id="github_profile" class="btn github" data-controls-modal="modal-generic" data-backdrop="static" data-keyboard="true" data-github-user="<%= github.username %>">Import from Repo</a><% }%>
+ <img src="/img/icon_octocat_20x20.png" class="icon_vendor github" alt="Octocat Icon"><% if(!loggedIn){ %>
+ <a href="https://github.com/login/oauth/authorize?client_id=<%- github.client_id %>&scope=repo&redirect_uri=<%- github.callback_url %>" id="oauth_github" class="btn vendor">Sign in With Github</a> |<% }%><% if(loggedIn){ %>
+ <a href="#" id="github_profile" class="btn vendor" data-controls-modal="modal-generic" data-backdrop="static" data-keyboard="true" data-github-user="<%= github.username %>">Import from Repo</a> |<% }%>
+ </span>
+ <span class="relative">
+ <img src="/img/icon_dropbox_16x16.png" class="icon_vendor dropbox" alt="Dropbox Icon"><% if(!dropbox.sync){ %>
+ <a href="https://www.dropbox.com/1/oauth/authorize?oauth_token=<%= dropbox.oauth_token %>&oauth_callback=<%= dropbox.oauth_callback %>" id="oauth_github" class="btn vendor">Link With Dropbox</a><% }%><% if(dropbox.sync){ %>
+ <a href="#" id="dropbox_profile" class="btn vendor" data-controls-modal="modal-generic" data-backdrop="static" data-keyboard="true" data-dropbox-user="<%= dropbox.username %>">Import from Dropbox</a><% }%>
</span>
<select id="theme">
<option value="ace/theme/clouds">Clouds</option>

0 comments on commit 31b8739

Please sign in to comment.