Skip to content

Commit f475bbb

Browse files
committed
Show a pop for oAuth dance
1 parent ea632cf commit f475bbb

File tree

4 files changed

+67
-25
lines changed

4 files changed

+67
-25
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: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,10 +1142,7 @@
11421142

11431143
$scope.context.forceRequest = false;
11441144

1145-
function pirula (type, scheme, collection, context) {
1146-
var details = $scope.securitySchemes[scheme].describedBy || {};
1147-
var securityHeaders = details[type] || {};
1148-
1145+
function cleanSchemeMetadata(collection, context) {
11491146
Object.keys(collection).map(function (key) {
11501147
if (collection[key][0].isFromSecurityScheme) {
11511148
delete collection[key];
@@ -1155,6 +1152,11 @@
11551152
delete context.plain[key];
11561153
}
11571154
});
1155+
}
1156+
1157+
function updateContextData (type, scheme, collection, context) {
1158+
var details = $scope.securitySchemes[scheme].describedBy || {};
1159+
var securityHeaders = details[type] || {};
11581160

11591161
if (securityHeaders) {
11601162
Object.keys(securityHeaders).map(function (key) {
@@ -1185,12 +1187,17 @@
11851187

11861188
$scope.currentSchemeType = type;
11871189

1188-
if (!$scope.methodInfo.headers.plain) {
1189-
$scope.methodInfo.headers.plain = {};
1190-
}
1190+
cleanSchemeMetadata($scope.methodInfo.headers.plain, $scope.context.headers);
1191+
cleanSchemeMetadata($scope.methodInfo.queryParameters, $scope.context.queryParameters);
1192+
1193+
if (type === 'x-custom') {
1194+
if (!$scope.methodInfo.headers.plain) {
1195+
$scope.methodInfo.headers.plain = {};
1196+
}
11911197

1192-
pirula('headers', name, $scope.methodInfo.headers.plain, $scope.context.headers);
1193-
pirula('queryParameters', name, $scope.methodInfo.queryParameters, $scope.context.queryParameters);
1198+
updateContextData('headers', name, $scope.methodInfo.headers.plain, $scope.context.headers);
1199+
updateContextData('queryParameters', name, $scope.methodInfo.queryParameters, $scope.context.queryParameters);
1200+
}
11941201
};
11951202

11961203
$scope.tryIt = function ($event) {
@@ -2297,6 +2304,14 @@
22972304
this.credentials = credentials;
22982305
};
22992306

2307+
function popup(location) {
2308+
var w = 640;
2309+
var h = 480;
2310+
var left = (screen.width / 2) - (w / 2);
2311+
var top = (screen.height / 2) - (h / 2);
2312+
return window.open(location, 'Authentication', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
2313+
}
2314+
23002315
Oauth2.prototype.authenticate = function(options, done) {
23012316
var auth = new ClientOAuth2({
23022317
clientId: this.credentials.clientId,
@@ -2323,7 +2338,7 @@
23232338
});
23242339
};
23252340
//// TODO: Find a way to handle 404
2326-
window.open(auth[grantType].getUri());
2341+
popup(auth[grantType].getUri());
23272342
}
23282343

23292344
if (grantType === 'owner') {
@@ -2334,6 +2349,9 @@
23342349

23352350
if (user && user.accessToken) {
23362351
user.request(options, function (err, res) {
2352+
res.raw.oauth = {
2353+
accessToken: user.accessToken
2354+
};
23372355
done(res.raw, err);
23382356
});
23392357
}

src/app/directives/sidebar.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,7 @@
264264

265265
$scope.context.forceRequest = false;
266266

267-
function pirula (type, scheme, collection, context) {
268-
var details = $scope.securitySchemes[scheme].describedBy || {};
269-
var securityHeaders = details[type] || {};
270-
267+
function cleanSchemeMetadata(collection, context) {
271268
Object.keys(collection).map(function (key) {
272269
if (collection[key][0].isFromSecurityScheme) {
273270
delete collection[key];
@@ -277,6 +274,11 @@
277274
delete context.plain[key];
278275
}
279276
});
277+
}
278+
279+
function updateContextData (type, scheme, collection, context) {
280+
var details = $scope.securitySchemes[scheme].describedBy || {};
281+
var securityHeaders = details[type] || {};
280282

281283
if (securityHeaders) {
282284
Object.keys(securityHeaders).map(function (key) {
@@ -307,12 +309,17 @@
307309

308310
$scope.currentSchemeType = type;
309311

310-
if (!$scope.methodInfo.headers.plain) {
311-
$scope.methodInfo.headers.plain = {};
312-
}
312+
cleanSchemeMetadata($scope.methodInfo.headers.plain, $scope.context.headers);
313+
cleanSchemeMetadata($scope.methodInfo.queryParameters, $scope.context.queryParameters);
313314

314-
pirula('headers', name, $scope.methodInfo.headers.plain, $scope.context.headers);
315-
pirula('queryParameters', name, $scope.methodInfo.queryParameters, $scope.context.queryParameters);
315+
if (type === 'x-custom') {
316+
if (!$scope.methodInfo.headers.plain) {
317+
$scope.methodInfo.headers.plain = {};
318+
}
319+
320+
updateContextData('headers', name, $scope.methodInfo.headers.plain, $scope.context.headers);
321+
updateContextData('queryParameters', name, $scope.methodInfo.queryParameters, $scope.context.queryParameters);
322+
}
316323
};
317324

318325
$scope.tryIt = function ($event) {

src/common/client/auth_strategies/oauth2.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
this.credentials = credentials;
77
};
88

9+
function popup(location) {
10+
var w = 640;
11+
var h = 480;
12+
var left = (screen.width / 2) - (w / 2);
13+
var top = (screen.height / 2) - (h / 2);
14+
return window.open(location, 'Authentication', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
15+
}
16+
917
Oauth2.prototype.authenticate = function(options, done) {
1018
var auth = new ClientOAuth2({
1119
clientId: this.credentials.clientId,
@@ -32,7 +40,7 @@
3240
});
3341
};
3442
//// TODO: Find a way to handle 404
35-
window.open(auth[grantType].getUri());
43+
popup(auth[grantType].getUri());
3644
}
3745

3846
if (grantType === 'owner') {
@@ -43,6 +51,9 @@
4351

4452
if (user && user.accessToken) {
4553
user.request(options, function (err, res) {
54+
res.raw.oauth = {
55+
accessToken: user.accessToken
56+
};
4657
done(res.raw, err);
4758
});
4859
}

0 commit comments

Comments
 (0)