fix jQuery JSON POST/PUT/PATCH request, move lint to oauth3.lint.js
This commit is contained in:
parent
2d10171de7
commit
73405e6742
@ -68,12 +68,16 @@
|
|||||||
, method: opts.method
|
, method: opts.method
|
||||||
// leaving type for backwards compat
|
// leaving type for backwards compat
|
||||||
, type: opts.method
|
, type: opts.method
|
||||||
, headers: opts.headers
|
, headers: opts.headers || {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// don't allow accidetal querystring via 'data'
|
// don't allow accidetal querystring via 'data'
|
||||||
if (opts.data && !/get|delete/i.test(opts.method)) {
|
if (opts.data && !/get|delete/i.test(opts.method)) {
|
||||||
req.data = opts.data;
|
req.data = opts.data;
|
||||||
|
if (opts.data && 'object' === typeof opts.data) {
|
||||||
|
req.data = JSON.stringify(req.data);
|
||||||
|
req.headers['Content-Type'] = 'application/json; charset=utf-8';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// I don't trust jQuery promises...
|
// I don't trust jQuery promises...
|
||||||
|
70
oauth3.js
70
oauth3.js
@ -23,62 +23,16 @@
|
|||||||
console.warn("[oauth3.js] Remember to call oauth3.providePromise(Promise) with a proper Promise implementation");
|
console.warn("[oauth3.js] Remember to call oauth3.providePromise(Promise) with a proper Promise implementation");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO move to a test / lint suite?
|
|
||||||
oauth3._testPromise = function (PromiseA) {
|
|
||||||
var promise;
|
|
||||||
var x = 1;
|
|
||||||
|
|
||||||
// tests that this promise has all of the necessary api
|
|
||||||
promise = new PromiseA(function (resolve, reject) {
|
|
||||||
//console.log('x [2]', x);
|
|
||||||
if (x !== 1) {
|
|
||||||
throw new Error("bad promise, create not Synchronous [0]");
|
|
||||||
}
|
|
||||||
|
|
||||||
PromiseA.resolve().then(function () {
|
|
||||||
var promise2;
|
|
||||||
|
|
||||||
//console.log('x resolve', x);
|
|
||||||
if (x !== 2) {
|
|
||||||
throw new Error("bad promise, resolve not Asynchronous [1]");
|
|
||||||
}
|
|
||||||
|
|
||||||
promise2 = PromiseA.reject().then(reject, function () {
|
|
||||||
//console.log('x reject', x);
|
|
||||||
if (x !== 4) {
|
|
||||||
throw new Error("bad promise, reject not Asynchronous [2]");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('undefined' === typeof angular) {
|
|
||||||
throw new Error("[NOT AN ERROR] Dear angular users: ignore this error-handling test");
|
|
||||||
} else {
|
|
||||||
return PromiseA.reject(new Error("[NOT AN ERROR] ignore this error-handling test"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
x = 4;
|
|
||||||
|
|
||||||
return promise2;
|
|
||||||
}).catch(function (e) {
|
|
||||||
if (e.message.match('NOT AN ERROR')) {
|
|
||||||
resolve({ success: true });
|
|
||||||
} else {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
x = 3;
|
|
||||||
});
|
|
||||||
|
|
||||||
x = 2;
|
|
||||||
return promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
oauth3.providePromise = function (PromiseA) {
|
oauth3.providePromise = function (PromiseA) {
|
||||||
oauth3.PromiseA = PromiseA;
|
oauth3.PromiseA = PromiseA;
|
||||||
return oauth3._testPromise(PromiseA).then(function () {
|
if (oauth3._testPromise) {
|
||||||
oauth3.PromiseA = PromiseA;
|
return oauth3._testPromise(PromiseA).then(function () {
|
||||||
});
|
oauth3.PromiseA = PromiseA;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
oauth3.PromiseA = PromiseA;
|
||||||
|
return PromiseA.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
oauth3._recaseRequest = function (recase, req) {
|
oauth3._recaseRequest = function (recase, req) {
|
||||||
@ -389,13 +343,13 @@
|
|||||||
var $iframe;
|
var $iframe;
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
delete window['__oauth3_' + state];
|
delete window['--oauth3-callback-' + state];
|
||||||
$iframe.remove();
|
$iframe.remove();
|
||||||
clearTimeout(tok);
|
clearTimeout(tok);
|
||||||
tok = null;
|
tok = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
window['__oauth3_' + state] = function (params) {
|
window['--oauth3-callback-' + state] = function (params) {
|
||||||
//console.info('[iframe] complete', params);
|
//console.info('[iframe] complete', params);
|
||||||
resolve(params);
|
resolve(params);
|
||||||
cleanup();
|
cleanup();
|
||||||
@ -428,7 +382,7 @@
|
|||||||
var tok;
|
var tok;
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
delete window['__oauth3_' + state];
|
delete window['--oauth3-callback-' + state];
|
||||||
clearTimeout(tok);
|
clearTimeout(tok);
|
||||||
tok = null;
|
tok = null;
|
||||||
// this is last in case the window self-closes synchronously
|
// this is last in case the window self-closes synchronously
|
||||||
@ -436,7 +390,7 @@
|
|||||||
//winref.close();
|
//winref.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
window['__oauth3_' + state] = function (params) {
|
window['--oauth3-callback-' + state] = function (params) {
|
||||||
//console.info('[popup] (or window) complete', params);
|
//console.info('[popup] (or window) complete', params);
|
||||||
resolve(params);
|
resolve(params);
|
||||||
cleanup();
|
cleanup();
|
||||||
|
50
oauth3.lint.js
Normal file
50
oauth3.lint.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// TODO move to a test / lint suite?
|
||||||
|
oauth3._testPromise = function (PromiseA) {
|
||||||
|
var promise;
|
||||||
|
var x = 1;
|
||||||
|
|
||||||
|
// tests that this promise has all of the necessary api
|
||||||
|
promise = new PromiseA(function (resolve, reject) {
|
||||||
|
//console.log('x [2]', x);
|
||||||
|
if (x !== 1) {
|
||||||
|
throw new Error("bad promise, create not Synchronous [0]");
|
||||||
|
}
|
||||||
|
|
||||||
|
PromiseA.resolve().then(function () {
|
||||||
|
var promise2;
|
||||||
|
|
||||||
|
//console.log('x resolve', x);
|
||||||
|
if (x !== 2) {
|
||||||
|
throw new Error("bad promise, resolve not Asynchronous [1]");
|
||||||
|
}
|
||||||
|
|
||||||
|
promise2 = PromiseA.reject().then(reject, function () {
|
||||||
|
//console.log('x reject', x);
|
||||||
|
if (x !== 4) {
|
||||||
|
throw new Error("bad promise, reject not Asynchronous [2]");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('undefined' === typeof angular) {
|
||||||
|
throw new Error("[NOT AN ERROR] Dear angular users: ignore this error-handling test");
|
||||||
|
} else {
|
||||||
|
return PromiseA.reject(new Error("[NOT AN ERROR] ignore this error-handling test"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
x = 4;
|
||||||
|
|
||||||
|
return promise2;
|
||||||
|
}).catch(function (e) {
|
||||||
|
if (e.message.match('NOT AN ERROR')) {
|
||||||
|
resolve({ success: true });
|
||||||
|
} else {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
x = 3;
|
||||||
|
});
|
||||||
|
|
||||||
|
x = 2;
|
||||||
|
return promise;
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user