Skip to content

Commit dd5e547

Browse files
author
Pavel Strashkin
committed
Fix oauth2
1 parent d886cc4 commit dd5e547

File tree

5 files changed

+61
-55
lines changed

5 files changed

+61
-55
lines changed

dist/scripts/api-console-vendor.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var block = {
2020
lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
2121
blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
2222
list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
23-
html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/,
23+
html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
2424
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
2525
table: noop,
2626
paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
@@ -868,7 +868,7 @@ Renderer.prototype.link = function(href, title, text) {
868868
} catch (e) {
869869
return '';
870870
}
871-
if (prot.indexOf('javascript:') === 0) {
871+
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
872872
return '';
873873
}
874874
}
@@ -1154,8 +1154,13 @@ function marked(src, opt, callback) {
11541154

11551155
pending = tokens.length;
11561156

1157-
var done = function() {
1158-
var out, err;
1157+
var done = function(err) {
1158+
if (err) {
1159+
opt.highlight = highlight;
1160+
return callback(err);
1161+
}
1162+
1163+
var out;
11591164

11601165
try {
11611166
out = Parser.parse(tokens, opt);
@@ -1184,6 +1189,7 @@ function marked(src, opt, callback) {
11841189
return --pending || done();
11851190
}
11861191
return highlight(token.text, token.lang, function(err, code) {
1192+
if (err) return done(err);
11871193
if (code == null || code === token.text) {
11881194
return --pending || done();
11891195
}
@@ -1253,7 +1259,7 @@ marked.inlineLexer = InlineLexer.output;
12531259

12541260
marked.parse = marked;
12551261

1256-
if (typeof exports === 'object') {
1262+
if (typeof module !== 'undefined' && typeof exports === 'object') {
12571263
module.exports = marked;
12581264
} else if (typeof define === 'function' && define.amd) {
12591265
define(function() { return marked; });

dist/scripts/api-console.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,7 @@
20722072
var options = request.toOptions();
20732073

20742074
return [
2075-
options.type.toUpperCase(),
2075+
options.method.toUpperCase(),
20762076
this.encodeURI(options.url),
20772077
rfc3986Encode(this.encodeParameters(request, oauthParams))
20782078
].join('&');
@@ -2428,7 +2428,7 @@
24282428

24292429
RAML.Client.Request = {
24302430
create: function(url, method) {
2431-
return new RequestDsl({ url: url, type: method });
2431+
return new RequestDsl({ url: url, method: method });
24322432
}
24332433
};
24342434
})();
@@ -3590,8 +3590,8 @@ RAML.Inspector = (function() {
35903590
var xhr = new root.XMLHttpRequest();
35913591
var headers = options.headers || {};
35923592

3593-
// Open the request to the uri and method.
3594-
xhr.open(options.method, options.uri);
3593+
// Open the request to the url and method.
3594+
xhr.open(options.method, options.url);
35953595

35963596
// When the request has loaded, attempt to automatically parse the body.
35973597
xhr.onload = function () {
@@ -3628,20 +3628,20 @@ RAML.Inspector = (function() {
36283628
* @param {Function} done
36293629
*/
36303630
ClientOAuth2.prototype.request = function (options, done) {
3631-
var lib = http;
3632-
var reqOpts = url.parse(options.uri);
3631+
var lib = http;
3632+
var reqOptions = url.parse(options.url);
36333633

36343634
// If the protocol is over https, switch request library.
3635-
if (reqOpts.protocol === 'https:') {
3635+
if (reqOptions.protocol === 'https:') {
36363636
lib = https;
36373637
}
36383638

36393639
// Alias request options.
3640-
reqOpts.method = options.method;
3641-
reqOpts.headers = options.headers;
3640+
reqOptions.method = options.method;
3641+
reqOptions.headers = options.headers;
36423642

36433643
// Send the http request and listen for the response to finish.
3644-
var req = lib.request(reqOpts, function (res) {
3644+
var req = lib.request(reqOptions, function (res) {
36453645
var data = '';
36463646

36473647
// Callback to `done` if a response error occurs.
@@ -3701,44 +3701,44 @@ RAML.Inspector = (function() {
37013701
/**
37023702
* Sign a standardised request object with user authentication information.
37033703
*
3704-
* @param {Object} opts
3704+
* @param {Object} options
37053705
* @return {Object}
37063706
*/
3707-
ClientOAuth2Token.prototype.sign = function (opts) {
3707+
ClientOAuth2Token.prototype.sign = function (options) {
37083708
if (!this.accessToken) {
37093709
throw new Error('Unable to sign without access token');
37103710
}
37113711

3712-
opts.headers = opts.headers || {};
3712+
options.headers = options.headers || {};
37133713

37143714
if (this.tokenType === 'bearer') {
3715-
opts.headers.Authorization = 'Bearer ' + this.accessToken;
3715+
options.headers.Authorization = 'Bearer ' + this.accessToken;
37163716
} else {
3717-
var parts = opts.uri.split('#');
3717+
var parts = options.url.split('#');
37183718
var token = 'access_token=' + this.accessToken;
3719-
var uri = parts[0].replace(/[?&]access_token=[^&#]/, '');
3719+
var url = parts[0].replace(/[?&]access_token=[^&#]/, '');
37203720
var fragment = parts[1] ? '#' + parts[1] : '';
37213721

3722-
// Prepend the correct query string parameter to the uri.
3723-
opts.uri = uri + (uri.indexOf('?') > -1 ? '&' : '?') + token + fragment;
3722+
// Prepend the correct query string parameter to the url.
3723+
options.url = url + (url.indexOf('?') > -1 ? '&' : '?') + token + fragment;
37243724

3725-
// Attempt to avoid storing the uri in proxies, since the access token
3725+
// Attempt to avoid storing the url in proxies, since the access token
37263726
// is exposed in the query parameters.
3727-
opts.headers.Pragma = 'no-store';
3728-
opts.headers['Cache-Control'] = 'no-store';
3727+
options.headers.Pragma = 'no-store';
3728+
options.headers['Cache-Control'] = 'no-store';
37293729
}
37303730

3731-
return opts;
3731+
return options;
37323732
};
37333733

37343734
/**
37353735
* Make a HTTP request as the user.
37363736
*
3737-
* @param {Object} opts
3737+
* @param {Object} options
37383738
* @param {Function} done
37393739
*/
3740-
ClientOAuth2Token.prototype.request = function (opts, done) {
3741-
return this.client.client.request(this.sign(opts), done);
3740+
ClientOAuth2Token.prototype.request = function (options, done) {
3741+
return this.client.client.request(this.sign(options), done);
37423742
};
37433743

37443744
/**

src/common/client/auth_strategies/oauth1/signer/hmac.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
var options = request.toOptions();
2323

2424
return [
25-
options.type.toUpperCase(),
25+
options.method.toUpperCase(),
2626
this.encodeURI(options.url),
2727
rfc3986Encode(this.encodeParameters(request, oauthParams))
2828
].join('&');

src/common/client/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105

106106
RAML.Client.Request = {
107107
create: function(url, method) {
108-
return new RequestDsl({ url: url, type: method });
108+
return new RequestDsl({ url: url, method: method });
109109
}
110110
};
111111
})();

src/vendor/client-oauth2/client-oauth2.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@
362362
var xhr = new root.XMLHttpRequest();
363363
var headers = options.headers || {};
364364

365-
// Open the request to the uri and method.
366-
xhr.open(options.method, options.uri);
365+
// Open the request to the url and method.
366+
xhr.open(options.method, options.url);
367367

368368
// When the request has loaded, attempt to automatically parse the body.
369369
xhr.onload = function () {
@@ -400,20 +400,20 @@
400400
* @param {Function} done
401401
*/
402402
ClientOAuth2.prototype.request = function (options, done) {
403-
var lib = http;
404-
var reqOpts = url.parse(options.uri);
403+
var lib = http;
404+
var reqOptions = url.parse(options.url);
405405

406406
// If the protocol is over https, switch request library.
407-
if (reqOpts.protocol === 'https:') {
407+
if (reqOptions.protocol === 'https:') {
408408
lib = https;
409409
}
410410

411411
// Alias request options.
412-
reqOpts.method = options.method;
413-
reqOpts.headers = options.headers;
412+
reqOptions.method = options.method;
413+
reqOptions.headers = options.headers;
414414

415415
// Send the http request and listen for the response to finish.
416-
var req = lib.request(reqOpts, function (res) {
416+
var req = lib.request(reqOptions, function (res) {
417417
var data = '';
418418

419419
// Callback to `done` if a response error occurs.
@@ -473,44 +473,44 @@
473473
/**
474474
* Sign a standardised request object with user authentication information.
475475
*
476-
* @param {Object} opts
476+
* @param {Object} options
477477
* @return {Object}
478478
*/
479-
ClientOAuth2Token.prototype.sign = function (opts) {
479+
ClientOAuth2Token.prototype.sign = function (options) {
480480
if (!this.accessToken) {
481481
throw new Error('Unable to sign without access token');
482482
}
483483

484-
opts.headers = opts.headers || {};
484+
options.headers = options.headers || {};
485485

486486
if (this.tokenType === 'bearer') {
487-
opts.headers.Authorization = 'Bearer ' + this.accessToken;
487+
options.headers.Authorization = 'Bearer ' + this.accessToken;
488488
} else {
489-
var parts = opts.uri.split('#');
489+
var parts = options.url.split('#');
490490
var token = 'access_token=' + this.accessToken;
491-
var uri = parts[0].replace(/[?&]access_token=[^&#]/, '');
491+
var url = parts[0].replace(/[?&]access_token=[^&#]/, '');
492492
var fragment = parts[1] ? '#' + parts[1] : '';
493493

494-
// Prepend the correct query string parameter to the uri.
495-
opts.uri = uri + (uri.indexOf('?') > -1 ? '&' : '?') + token + fragment;
494+
// Prepend the correct query string parameter to the url.
495+
options.url = url + (url.indexOf('?') > -1 ? '&' : '?') + token + fragment;
496496

497-
// Attempt to avoid storing the uri in proxies, since the access token
497+
// Attempt to avoid storing the url in proxies, since the access token
498498
// is exposed in the query parameters.
499-
opts.headers.Pragma = 'no-store';
500-
opts.headers['Cache-Control'] = 'no-store';
499+
options.headers.Pragma = 'no-store';
500+
options.headers['Cache-Control'] = 'no-store';
501501
}
502502

503-
return opts;
503+
return options;
504504
};
505505

506506
/**
507507
* Make a HTTP request as the user.
508508
*
509-
* @param {Object} opts
509+
* @param {Object} options
510510
* @param {Function} done
511511
*/
512-
ClientOAuth2Token.prototype.request = function (opts, done) {
513-
return this.client.client.request(this.sign(opts), done);
512+
ClientOAuth2Token.prototype.request = function (options, done) {
513+
return this.client.client.request(this.sign(options), done);
514514
};
515515

516516
/**

0 commit comments

Comments
 (0)