Skip to content

Commit

Permalink
version 0.4.30 - add trello service
Browse files Browse the repository at this point in the history
  • Loading branch information
falexandrou committed Jul 20, 2014
1 parent 8d193a9 commit 920776b
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -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/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/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)) <img src="https://github.com/jed/authom/raw/master/lib/assets/vkontakte.ico" style="vertical-align:middle"> Vkontakte (by [molforp](https://github.com/molforp))
Expand Down Expand Up @@ -561,6 +563,26 @@ var soundcloud = authom.createServer({
}) })
``` ```


### Trello ([create an app](https://trello.com/docs/gettingstarted/index.html#getting-an-application-key))

Options:

- `service`: "trello"
- `id`: the application's `Consumer key`
- `secret`: the application's `Consumer secret`
- `app_name`: the application's `name`

Example:

```javascript
var trello = authom.createServer({
service: "trello",
id: "LwjCfHAugMghuYtHLS9Ugw",
secret: "etam3XHqDSDPceyHti6tRQGoywiISY0vZWfzhQUxGL4",
app_name: "Coolest app in the world"
})
```

### Twitter ([create an app](dev.twitter.com/apps/)) ### Twitter ([create an app](dev.twitter.com/apps/))


Options: Options:
Expand Down
Binary file added lib/assets/trello.ico
Binary file not shown.
75 changes: 75 additions & 0 deletions 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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Jed Schmidt <tr@nslator.jp> (http://jed.is)", "author": "Jed Schmidt <tr@nslator.jp> (http://jed.is)",
"name": "authom", "name": "authom",
"description": "A dependency-free multi-service authentication tool for node.js", "description": "A dependency-free multi-service authentication tool for node.js",
"version": "0.4.29", "version": "0.4.30",
"keywords": [ "keywords": [
"auth", "auth",
"authorization", "authorization",
Expand Down

0 comments on commit 920776b

Please sign in to comment.