Skip to content

Commit 6a8d2f6

Browse files
author
Javier Centurion
committed
Fixing oAuth error with wrong credentials
1 parent 28b2f0b commit 6a8d2f6

File tree

6 files changed

+52
-46
lines changed

6 files changed

+52
-46
lines changed

dist/examples/leagues.raml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ securitySchemes:
3434
settings:
3535
authorizationUri: https://github.com/login/oauth/authorize
3636
accessTokenUri: https://github.com/login/oauth/access_token
37-
authorizationGrants: [ code ]
37+
authorizationGrants: [ code, credentials, owner ]
3838
scopes:
3939
- "user"
4040
- "user:email"

dist/scripts/api-console.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -922,21 +922,24 @@
922922
return body;
923923
}
924924

925-
function handleResponse(jqXhr) {
926-
$scope.response.status = jqXhr.status;
927-
$scope.response.headers = parseHeaders(jqXhr.getAllResponseHeaders());
925+
function handleResponse(jqXhr, err) {
926+
$scope.response.status = jqXhr ? jqXhr.status : err ? err.status : 0;
928927

929-
$scope.currentStatusCode = jqXhr.status.toString();
928+
if (jqXhr) {
929+
$scope.response.headers = parseHeaders(jqXhr.getAllResponseHeaders());
930930

931-
if ($scope.response.headers['content-type']) {
932-
$scope.response.contentType = $scope.response.headers['content-type'].split(';')[0];
933-
}
931+
if ($scope.response.headers['content-type']) {
932+
$scope.response.contentType = $scope.response.headers['content-type'].split(';')[0];
933+
}
934934

935-
try {
936-
$scope.response.body = beautify(jqXhr.responseText, $scope.response.contentType);
937-
}
938-
catch (e) {
939-
$scope.response.body = jqXhr.responseText;
935+
$scope.currentStatusCode = jqXhr.status.toString();
936+
937+
try {
938+
$scope.response.body = beautify(jqXhr.responseText, $scope.response.contentType);
939+
}
940+
catch (e) {
941+
$scope.response.body = jqXhr.responseText;
942+
}
940943
}
941944

942945
$scope.requestEnd = true;
@@ -951,7 +954,7 @@
951954
// If the response fails because of CORS, responseText is null
952955
var editorHeight = 50;
953956

954-
if (jqXhr.responseText) {
957+
if (jqXhr && jqXhr.responseText) {
955958
var lines = $scope.response.body.split('\n').length;
956959
editorHeight = lines > 100 ? 2000 : 25*lines;
957960
}
@@ -1191,9 +1194,9 @@
11911194
//// TODO: Make a uniform interface
11921195
if (scheme && scheme.type === 'OAuth 2.0') {
11931196
authStrategy = new RAML.Client.AuthStrategies.Oauth2(scheme, $scope.credentials);
1194-
authStrategy.authenticate(request.toOptions(), function (jqXhr) {
1197+
authStrategy.authenticate(request.toOptions(), function (jqXhr, err) {
11951198
$scope.requestOptions = request.toOptions();
1196-
handleResponse(jqXhr);
1199+
handleResponse(jqXhr, err);
11971200
});
11981201
return;
11991202
}
@@ -2245,12 +2248,12 @@
22452248
window.oauth2Callback = function (uri) {
22462249
auth[grantType].getToken(uri, function (err, user, raw) {
22472250
if (err) {
2248-
done(raw);
2251+
done(raw, err);
22492252
}
22502253

22512254
if (user && user.accessToken) {
22522255
user.request(options, function (err, res) {
2253-
done(res.raw);
2256+
done(res.raw, err);
22542257
});
22552258
}
22562259
});
@@ -2262,12 +2265,12 @@
22622265
if (grantType === 'owner') {
22632266
auth.owner.getToken(this.credentials.username, this.credentials.password, function (err, user, raw) {
22642267
if (err) {
2265-
done(raw);
2268+
done(raw, err);
22662269
}
22672270

22682271
if (user && user.accessToken) {
22692272
user.request(options, function (err, res) {
2270-
done(res.raw);
2273+
done(res.raw, err);
22712274
});
22722275
}
22732276
});
@@ -2276,12 +2279,12 @@
22762279
if (grantType === 'credentials') {
22772280
auth.credentials.getToken(function (err, user, raw) {
22782281
if (err) {
2279-
done(raw);
2282+
done(raw, err);
22802283
}
22812284

22822285
if (user && user.accessToken) {
22832286
user.request(options, function (err, res) {
2284-
done(res.raw);
2287+
done(res.raw, err);
22852288
});
22862289
}
22872290
});
@@ -5350,7 +5353,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
53505353
" <h3 class=\"raml-console-sidebar-response-head\">Status</h3>\n" +
53515354
" <p class=\"raml-console-sidebar-response-item\">{{response.status}}</p>\n" +
53525355
"\n" +
5353-
" <h3 class=\"raml-console-sidebar-response-head\">Headers</h3>\n" +
5356+
" <h3 class=\"raml-console-sidebar-response-head\" ng-if=\"response.headers\">Headers</h3>\n" +
53545357
" <div class=\"raml-console-sidebar-response-item\">\n" +
53555358
" <p class=\"raml-console-sidebar-response-metadata\" ng-repeat=\"(key, value) in response.headers\">\n" +
53565359
" <b>{{key}}:</b> <br>{{value}}\n" +

src/app/directives/sidebar.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,24 @@
5454
return body;
5555
}
5656

57-
function handleResponse(jqXhr) {
58-
$scope.response.status = jqXhr.status;
59-
$scope.response.headers = parseHeaders(jqXhr.getAllResponseHeaders());
57+
function handleResponse(jqXhr, err) {
58+
$scope.response.status = jqXhr ? jqXhr.status : err ? err.status : 0;
6059

61-
$scope.currentStatusCode = jqXhr.status.toString();
60+
if (jqXhr) {
61+
$scope.response.headers = parseHeaders(jqXhr.getAllResponseHeaders());
6262

63-
if ($scope.response.headers['content-type']) {
64-
$scope.response.contentType = $scope.response.headers['content-type'].split(';')[0];
65-
}
63+
if ($scope.response.headers['content-type']) {
64+
$scope.response.contentType = $scope.response.headers['content-type'].split(';')[0];
65+
}
6666

67-
try {
68-
$scope.response.body = beautify(jqXhr.responseText, $scope.response.contentType);
69-
}
70-
catch (e) {
71-
$scope.response.body = jqXhr.responseText;
67+
$scope.currentStatusCode = jqXhr.status.toString();
68+
69+
try {
70+
$scope.response.body = beautify(jqXhr.responseText, $scope.response.contentType);
71+
}
72+
catch (e) {
73+
$scope.response.body = jqXhr.responseText;
74+
}
7275
}
7376

7477
$scope.requestEnd = true;
@@ -83,7 +86,7 @@
8386
// If the response fails because of CORS, responseText is null
8487
var editorHeight = 50;
8588

86-
if (jqXhr.responseText) {
89+
if (jqXhr && jqXhr.responseText) {
8790
var lines = $scope.response.body.split('\n').length;
8891
editorHeight = lines > 100 ? 2000 : 25*lines;
8992
}
@@ -323,9 +326,9 @@
323326
//// TODO: Make a uniform interface
324327
if (scheme && scheme.type === 'OAuth 2.0') {
325328
authStrategy = new RAML.Client.AuthStrategies.Oauth2(scheme, $scope.credentials);
326-
authStrategy.authenticate(request.toOptions(), function (jqXhr) {
329+
authStrategy.authenticate(request.toOptions(), function (jqXhr, err) {
327330
$scope.requestOptions = request.toOptions();
328-
handleResponse(jqXhr);
331+
handleResponse(jqXhr, err);
329332
});
330333
return;
331334
}

src/app/directives/sidebar.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ <h3 class="raml-console-sidebar-head">
160160
<h3 class="raml-console-sidebar-response-head">Status</h3>
161161
<p class="raml-console-sidebar-response-item">{{response.status}}</p>
162162

163-
<h3 class="raml-console-sidebar-response-head">Headers</h3>
163+
<h3 class="raml-console-sidebar-response-head" ng-if="response.headers">Headers</h3>
164164
<div class="raml-console-sidebar-response-item">
165165
<p class="raml-console-sidebar-response-metadata" ng-repeat="(key, value) in response.headers">
166166
<b>{{key}}:</b> <br>{{value}}

src/assets/examples/leagues.raml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ securitySchemes:
3434
settings:
3535
authorizationUri: https://github.com/login/oauth/authorize
3636
accessTokenUri: https://github.com/login/oauth/access_token
37-
authorizationGrants: [ code ]
37+
authorizationGrants: [ code, credentials, owner ]
3838
scopes:
3939
- "user"
4040
- "user:email"

src/common/client/auth_strategies/oauth2.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
window.oauth2Callback = function (uri) {
2222
auth[grantType].getToken(uri, function (err, user, raw) {
2323
if (err) {
24-
done(raw);
24+
done(raw, err);
2525
}
2626

2727
if (user && user.accessToken) {
2828
user.request(options, function (err, res) {
29-
done(res.raw);
29+
done(res.raw, err);
3030
});
3131
}
3232
});
@@ -38,12 +38,12 @@
3838
if (grantType === 'owner') {
3939
auth.owner.getToken(this.credentials.username, this.credentials.password, function (err, user, raw) {
4040
if (err) {
41-
done(raw);
41+
done(raw, err);
4242
}
4343

4444
if (user && user.accessToken) {
4545
user.request(options, function (err, res) {
46-
done(res.raw);
46+
done(res.raw, err);
4747
});
4848
}
4949
});
@@ -52,12 +52,12 @@
5252
if (grantType === 'credentials') {
5353
auth.credentials.getToken(function (err, user, raw) {
5454
if (err) {
55-
done(raw);
55+
done(raw, err);
5656
}
5757

5858
if (user && user.accessToken) {
5959
user.request(options, function (err, res) {
60-
done(res.raw);
60+
done(res.raw, err);
6161
});
6262
}
6363
});

0 commit comments

Comments
 (0)