removed sub
as strict requirement for saving grants
This commit is contained in:
parent
189a9424cd
commit
95bc9869ad
15
grants.js
15
grants.js
@ -1,7 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var crypto = require('crypto');
|
||||||
var PromiseA = require('bluebird');
|
var PromiseA = require('bluebird');
|
||||||
var OpErr = PromiseA.OperationalError;
|
var OpErr = PromiseA.OperationalError;
|
||||||
|
var makeB64UrlSafe = require('./common').makeB64UrlSafe;
|
||||||
|
|
||||||
|
|
||||||
function trim(grant) {
|
function trim(grant) {
|
||||||
@ -39,10 +41,21 @@ function create(app) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
restful.saveNew = function (req, res) {
|
restful.saveNew = function (req, res) {
|
||||||
var promise = PromiseA.resolve().then(function () {
|
var promise = req.Store.get(req.params.sub+'/'+req.params.azp).then(function (existing) {
|
||||||
|
if (existing) {
|
||||||
|
if (req.body.sub && req.body.sub !== existing.azpSub) {
|
||||||
|
throw new OpErr("specified 'sub' does not agree with existing grants");
|
||||||
|
}
|
||||||
|
req.body.sub = existing.azpSub;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req.body.sub) {
|
||||||
|
req.body.sub = makeB64UrlSafe(crypto.randomBytes(32).toString('base64'));
|
||||||
|
}
|
||||||
if (typeof req.body.scope !== 'string' || typeof req.body.sub !== 'string') {
|
if (typeof req.body.scope !== 'string' || typeof req.body.sub !== 'string') {
|
||||||
throw new OpErr("malformed request: 'sub' and 'scope' must be strings");
|
throw new OpErr("malformed request: 'sub' and 'scope' must be strings");
|
||||||
}
|
}
|
||||||
|
|
||||||
return req.Store.find({ azpSub: req.body.sub });
|
return req.Store.find({ azpSub: req.body.sub });
|
||||||
}).then(function (existing) {
|
}).then(function (existing) {
|
||||||
if (existing.length) {
|
if (existing.length) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user