From ec430598753041d9ff07669b5010dc677e60eff4 Mon Sep 17 00:00:00 2001 From: asureddi Date: Fri, 17 Apr 2015 17:26:52 -0700 Subject: [PATCH] Support for Visual Studio Online --- README.md | 2 ++ lib/assets/vso.PNG | Bin 0 -> 749 bytes lib/services/oauth2.js | 17 +++++++++++++--- lib/services/vso.js | 44 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 lib/assets/vso.PNG create mode 100644 lib/services/vso.js diff --git a/README.md b/README.md index 05e632f..23ff3c0 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,8 @@ Supported services Ninja Blocks (by [thatguydan](https://github.com/thatguydan)) + Visual Studio Online (by [asureddi](https://github.com/asureddi)) + Installation and Setup ---------------------- diff --git a/lib/assets/vso.PNG b/lib/assets/vso.PNG new file mode 100644 index 0000000000000000000000000000000000000000..1dd8e3d30684589b464409fa8ee5e3e25a70b07e GIT binary patch literal 749 zcmVPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0)k0IK~zXf#g5y&J7y;B00=(g!=`)V3yR*xhQbAE#f+_fKo zLY&@yS?YFNlivCP`SWYZj?Qb{V4!UW?ih#*b>rx!v-0uP7yCqB|A3csEB30i=4Y~n z^hN|n6@S!`z})wF(Rs^}h(2=2c!Y`{90N!fj7V%CnxOKTbhCG7-@cYjL+52T*R@vV)< z3WV;wX-`_-4^Nsgq}OjG#t{!L44FmI!G8Knf@?RQGb^UnJir753!xM@Yws6Ls=I!1 z`?Z}#r0Yz7`C!@}Fd7{kH}%qBGB<@lukLL(r<7`Sd3F6@G&c0X?ABd?1}P==u7ZI% z2C1_r3jzj8S1Zg~Ro@D+-08*ADM3nBQOLxdAdRS_5;(=a|% ztwPORu)^IYD;rGO@G+CAH)*V=*GEhWRlu3dO}m1y+})FX<$-yDAE~M{6EZNh??#bT zTwyiF`2a#);ND9F&y0ODDdr*S=3B)Vhm5A%g+xUn81YJEK&j6b6+4dt`B4&FiL~L| zn)^Z11_z_Kn)5#m%eDXQ6$Fg*#i9$~FW$$dQ6GH4zz8^p48F$^ct1`-!H6T&^?jUz fga20>1QuBXI&PejrR;XK00000NkvXXu0mjfOYu_e literal 0 HcmV?d00001 diff --git a/lib/services/oauth2.js b/lib/services/oauth2.js index b6210ee..45e23c6 100644 --- a/lib/services/oauth2.js +++ b/lib/services/oauth2.js @@ -88,7 +88,11 @@ OAuth2.prototype.onStart = function(req, res) { } OAuth2.prototype.onCode = function(req, res) { - this.token.query.code = req.url.query.code + if (this.token.host == "app.vssps.visualstudio.com"){ + this.token.query.assertion = req.url.query.code + }else { + this.token.query.code = req.url.query.code + } delete req.url.query delete req.url.search @@ -101,17 +105,24 @@ OAuth2.prototype.onCode = function(req, res) { var tokenKey = this.user.tokenKey || "access_token" this.user.query[tokenKey] = data.access_token - + if (this.user.host == "oauth.reddit.com") { this.user.headers = {"Authorization": "bearer " + data.access_token}; } - + if (this.user.host == "api.stripe.com") { delete this.user.query[tokenKey]; this.user.headers = {"Authorization": "bearer " + data.access_token}; var stripe_publishable_key = data.stripe_publishable_key; } + if (this.user.host == "app.vssps.visualstudio.com") { + delete this.user.query[tokenKey]; + this.user.headers = {"Authorization": "bearer " + data.access_token, + "accept": "application/json; api-version=1.0", + "content-type": "application/json-patch+json "}; + } + this.request(this.user, function(err, user) { if (err) return this.emit("error", req, res, err) diff --git a/lib/services/vso.js b/lib/services/vso.js new file mode 100644 index 0000000..bdff7ba --- /dev/null +++ b/lib/services/vso.js @@ -0,0 +1,44 @@ +var OAuth2 = require("./oauth2") + , util = require("util") + +function vso(options) { + this.code.query = { + client_id: options.id, + response_type: "Assertion", + scope: options.scope + } + + this.token.query = { + client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", + client_assertion: options.secret, + grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer", + assertion: "" + } + + this.user.query = {} + + this.on("request", this.onRequest.bind(this)) + + OAuth2.call(this, options) +} + +util.inherits(vso, OAuth2) + +vso.prototype.code = { + protocol: "https", + host: "app.vssps.visualstudio.com", + pathname: "/oauth2/authorize" +} + +vso.prototype.token = { + method: "POST", + host: "app.vssps.visualstudio.com", + path: "/oauth2/token", + headers: { "Content-Type": "application/x-www-form-urlencoded" } +} + +vso.prototype.user = { + host: "app.vssps.visualstudio.com", + path: "/_apis/profile/profiles/me?api-version=1.0" +} +module.exports = vso