Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

version 0.4.30 - add trello service

  • Loading branch information...
commit b86f824a7e5909aa84932be280d57a82d3fd56fa 1 parent 8d193a9
@falexandrou authored
View
2  README.md
@@ -102,6 +102,8 @@ Supported services
<img src="https://github.com/jed/authom/raw/master/lib/assets/soundcloud.ico" style="vertical-align:middle"> SoundCloud (by [jed](https://github.com/jed))
+<img src="https://github.com/jed/authom/raw/master/lib/assets/trello.ico" style="vertical-align:middle"> Trello (by [falexandrou](https://github.com/falexandrou))
+
<img src="https://github.com/jed/authom/raw/master/lib/assets/twitter.ico" style="vertical-align:middle"> Twitter (by [jed](https://github.com/jed))
<img src="https://github.com/jed/authom/raw/master/lib/assets/vkontakte.ico" style="vertical-align:middle"> Vkontakte (by [molforp](https://github.com/molforp))
View
BIN  lib/assets/trello.ico
Binary file not shown
View
75 lib/services/trello.js
@@ -0,0 +1,75 @@
+var EventEmitter = require("events").EventEmitter
+ , util = require("util")
+ , url = require("url")
+ , OAuth
+ , secrets = {}
+
+try { OAuth = require("oauth").OAuth }
+catch (e) {
+ throw new Error("oauth library could not be loaded.")
+}
+
+function Trello(options) {
+ this.id = options.id
+ this.secret = options.secret
+ this.app_name = options.app_name
+
+ this.on("request", this.onRequest.bind(this))
+
+ EventEmitter.call(this);
+}
+
+util.inherits(Trello, EventEmitter);
+
+Trello.prototype.parseURI = function(request) {
+ var protocol = request.socket.encrypted ? "https" : "http"
+ , host = request.headers.host || request.connection.remoteAddress
+
+ return url.parse(protocol + "://" + host + request.url, true)
+}
+
+Trello.prototype.onRequest = function(req, res) {
+ var self = this
+ , uri = this.parseURI(req)
+ , verifier = uri.query.oauth_verifier
+ , token = uri.query.oauth_token
+ , oa = new OAuth(
+ "https://trello.com/1/OAuthGetRequestToken",
+ "https://trello.com/1/OAuthGetAccessToken",
+ this.id,
+ this.secret,
+ "1.0",
+ url.format(uri),
+ "HMAC-SHA1"
+ )
+
+ if (verifier && token) {
+ oa.getOAuthAccessToken(token, secrets[token], verifier, onToken)
+ }
+
+ else oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results){
+ if (error) return self.emit("error", req, res, uri.query, error)
+
+ secrets[oauth_token] = oauth_token_secret
+ setTimeout(function(){ delete secrets[oauth_token] }, 60000)
+
+ res.writeHead(302, {
+ Location: "https://trello.com/1/OAuthAuthorizeToken?oauth_token=" + oauth_token + (self.app_name !== undefined ? ('&name='+self.app_name) : '')
+ })
+
+ res.end()
+ })
+
+ function onToken(error, oauth_access_token, oauth_access_token_secret, results){
+ if (error) return self.emit("error", req, res, uri.query, error)
+
+ self.emit("auth", req, res, {
+ token: oauth_access_token,
+ secret: oauth_access_token_secret,
+ id: results.encoded_user_id,
+ data: results
+ })
+ }
+}
+
+module.exports = Trello
View
2  package.json
@@ -2,7 +2,7 @@
"author": "Jed Schmidt <tr@nslator.jp> (http://jed.is)",
"name": "authom",
"description": "A dependency-free multi-service authentication tool for node.js",
- "version": "0.4.29",
+ "version": "0.4.30",
"keywords": [
"auth",
"authorization",
Please sign in to comment.
Something went wrong with that request. Please try again.