-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5 - Added JSON API integration for Google Cloud.
There are some remaining CORS issues though.
- Loading branch information
Showing
14 changed files
with
296 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -420,6 +420,7 @@ Meteor core packages: | |
* tracker | ||
* reactive-var | ||
* check | ||
* http | ||
|
||
## API Reference | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* global oauth: true */ | ||
|
||
|
||
oauth = { | ||
|
||
Jwt: function (claim, scope) { | ||
_.defaults(claim, { | ||
aud: "https://www.googleapis.com/oauth2/v3/token" | ||
}); | ||
|
||
check(claim, { | ||
"iss": String, | ||
"aud": String, | ||
"sub": Match.Optional(String) | ||
}); | ||
|
||
check(scope, [String]); | ||
|
||
claim.scope = scope.join(" "); | ||
|
||
_.extend(this, { | ||
_claim: claim, | ||
_header: this.encode({ | ||
"alg": "RS256", | ||
"typ": "JWT" | ||
}) | ||
}); | ||
}, | ||
|
||
TokenGenerator: function (jwt, key) { | ||
check(jwt, oauth.Jwt); | ||
check(key, String); | ||
|
||
this.endpoint = "https://www.googleapis.com/oauth2/v3/token"; | ||
this.jwt = jwt; | ||
this.key = key; | ||
this.grantType = "urn:ietf:params:oauth:grant-type:jwt-bearer"; | ||
} | ||
}; | ||
|
||
_.extend(oauth.Jwt.prototype, { | ||
|
||
encode: function (object) { | ||
return new Buffer(JSON.stringify(object)).toString("base64"); | ||
}, | ||
|
||
sign: rsaSha256, | ||
|
||
makeClaim: function (iat, exp) { | ||
return this.encode(_.extend({ | ||
exp: Math.round(exp.getTime() / 1000), | ||
iat: Math.round(iat.getTime() / 1000) | ||
}, this._claim)); | ||
}, | ||
|
||
compile: function (key, iat, exp) { | ||
var jwt = this._header + "." + this.makeClaim(iat, exp); | ||
return jwt + "." + this.sign(jwt, key); | ||
} | ||
}); | ||
|
||
_.extend(oauth.TokenGenerator.prototype, { | ||
|
||
timeout: function () { | ||
if (!this._expires) | ||
return 0; | ||
|
||
return Math.max(this._expires.getTime() - Date.now(), 0); | ||
}, | ||
|
||
getToken: Meteor.wrapAsync(function (callback) { | ||
if (!this._token || this.timeout() < 60000) | ||
this.requestNewToken(callback); | ||
else | ||
callback(null, this._token); | ||
}), | ||
|
||
requestNewToken: Meteor.wrapAsync(function (callback) { | ||
var self = this, | ||
querystring = Npm.require("querystring"), | ||
iat = new Date(), | ||
exp = new Date(iat.getTime() + 3600 * 1000); | ||
|
||
delete this._token; | ||
delete this._expires; | ||
|
||
HTTP.post(this.endpoint, { | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
}, | ||
|
||
content: querystring.stringify({ | ||
grant_type: this.grantType, | ||
assertion: this.jwt.compile(this.key, iat, exp) | ||
}) | ||
}, function (error, response) { | ||
if (!error && response) { | ||
self._expires = new Date(iat.getTime() + | ||
response.data.expires_in * 1000); | ||
self._token = response.data.access_token; | ||
} | ||
|
||
callback(error, self._token); | ||
}); | ||
}) | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var crypto = Npm.require("crypto"); | ||
|
||
/* global rsaSha256: true */ | ||
rsaSha256 = function (data, key, encoding) { | ||
return crypto | ||
.createSign('RSA-SHA256') | ||
.update(data) | ||
.sign(key, encoding || "base64"); | ||
}; | ||
|
||
/* global hmac256: true */ | ||
hmac256 = function (key, data, encoding) { | ||
return crypto | ||
.createHmac("sha256", key) | ||
.update(new Buffer(data, "utf-8")) | ||
.digest(encoding); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ Package.describe({ | |
Package.on_use(function (api) { | ||
api.versionsFrom('[email protected]'); | ||
|
||
api.use("http", "server"); | ||
api.use(["underscore", "check"]); | ||
api.use(["tracker", "reactive-var"], "client"); | ||
|
||
|
@@ -19,10 +20,13 @@ Package.on_use(function (api) { | |
api.add_files("lib/upload.js", "client"); | ||
|
||
api.add_files([ | ||
"lib/utils.js", | ||
"lib/directive.js", | ||
"lib/storage-policy.js", | ||
"lib/oauth2.js", | ||
"services/aws-s3.js", | ||
"services/google-cloud.js", | ||
"services/google-cloud-resumable.js", | ||
"services/rackspace.js" | ||
], "server"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.