Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

its workin

  • Loading branch information...
commit b33f318929485244016e33f5ec8947f8cf53f7f2 1 parent ade8139
@tiankongldp tiankongldp authored
Showing with 15 additions and 4 deletions.
  1. +2 −1  examples/app.js
  2. +8 −0 lib/carta.js
  3. +5 −3 lib/middlewares.js
View
3  examples/app.js
@@ -12,8 +12,9 @@ app.configure(function(){
carta.configure(function() {
this.CURRENT_USER = function(req, callback) {
- callback(null, req.session.user);
+ callback(null, {id: 1});
};
+ this.createScopes(["read", "write"]);
});
app.get('/oauth/authorize', carta.authorize);
View
8 lib/carta.js
@@ -19,6 +19,14 @@ carta.Scope = require('./engines/memory').Scope;
carta.authorize = require('./middlewares').authorize;
+// helpers
+
carta.configure = function(fn) {
fn.apply(this);
+};
+
+carta.createScopes = function(arr) {
+ arr.forEach(function(i) {
+ carta.Scope.create({ name: i });
+ });
};
View
8 lib/middlewares.js
@@ -10,7 +10,7 @@ middlewares.authorize = function(req, res) {
if(req.query.response_type !== 'code' || !req.query.client_id)
return res.send(400);
- this.CURRENT_USER(req, function(err, user) {
+ carta.CURRENT_USER(req, function(err, user) {
if(err) return res.send(500);
var scopes = req.query.scopes || 'read';
@@ -26,13 +26,15 @@ middlewares.authorize = function(req, res) {
},
function(err) {
if(err) return res.send(500);
- carta.AuthGrant.create({
+ var grant = {
resource_owner: user.id,
code: utile.randomString(carta.GRANT_LENGTH),
scopes: JSON.stringify(scopes),
expires: moment().add('seconds', carta.EXPIRE_TIME).toString(),
client_id: req.query.client_id
- });
+ };
+ carta.AuthGrant.create(grant);
+ res.json(grant);
}
);
});
Please sign in to comment.
Something went wrong with that request. Please try again.