Skip to content

Commit 2524f17

Browse files
authored
Merge pull request #118 from oauthjs/bugfix/object-property-access
Validate object property access
2 parents ee05e4b + fbb34b3 commit 2524f17

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
},
2323
"homepage": "https://github.com/seegno/angular-oauth2",
2424
"dependencies": {
25-
"angular": "^1.4.0",
26-
"angular-cookies": "^1.4.0",
25+
"angular": "1.5.9",
26+
"angular-cookies": "1.5.9",
2727
"query-string": "^1.0.0"
2828
},
2929
"devDependencies": {
30-
"angular-mocks": "^1.3.9",
30+
"angular-mocks": "1.5.9",
3131
"github-changes": "^1.0.0",
3232
"gulp": "^3.8.10",
3333
"gulp-babel": "^5.3.0",

src/interceptors/oauth-interceptor.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ function oauthInterceptor($q, $rootScope, OAuthToken) {
1616
return config;
1717
},
1818
responseError: function(rejection) {
19+
if (!rejection) {
20+
return $q.reject(rejection);
21+
}
22+
1923
// Catch `invalid_request` and `invalid_grant` errors and ensure that the `token` is removed.
2024
if (400 === rejection.status && rejection.data &&
2125
('invalid_request' === rejection.data.error || 'invalid_grant' === rejection.data.error)
@@ -29,7 +33,7 @@ function oauthInterceptor($q, $rootScope, OAuthToken) {
2933
// The token isn't removed here so it can be refreshed when the `invalid_token` error occurs.
3034
if (401 === rejection.status &&
3135
(rejection.data && 'invalid_token' === rejection.data.error) ||
32-
(rejection.headers('www-authenticate') && 0 === rejection.headers('www-authenticate').indexOf('Bearer'))
36+
(rejection.headers && rejection.headers('www-authenticate') && 0 === rejection.headers('www-authenticate').indexOf('Bearer'))
3337
) {
3438
$rootScope.$emit('oauth:error', rejection);
3539
}

src/providers/oauth-token-provider.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,44 @@ function OAuthTokenProvider() {
6363
*/
6464

6565
getAccessToken() {
66-
return this.getToken() ? this.getToken().access_token : undefined;
66+
const { access_token } = this.getToken() || {};
67+
68+
return access_token;
6769
}
6870

6971
/**
7072
* Get authorizationHeader.
7173
*/
7274

7375
getAuthorizationHeader() {
74-
if (!(this.getTokenType() && this.getAccessToken())) {
76+
const tokenType = this.getTokenType();
77+
const accessToken = this.getAccessToken();
78+
79+
if (!tokenType || !accessToken) {
7580
return;
7681
}
7782

78-
return `${this.getTokenType().charAt(0).toUpperCase() + this.getTokenType().substr(1)} ${this.getAccessToken()}`;
83+
return `${tokenType.charAt(0).toUpperCase() + tokenType.substr(1)} ${accessToken}`;
7984
}
8085

8186
/**
8287
* Get refreshToken.
8388
*/
8489

8590
getRefreshToken() {
86-
return this.getToken() ? this.getToken().refresh_token : undefined;
91+
const { refresh_token } = this.getToken() || {};
92+
93+
return refresh_token;
8794
}
8895

8996
/**
9097
* Get tokenType.
9198
*/
9299

93100
getTokenType() {
94-
return this.getToken() ? this.getToken().token_type : undefined;
101+
const { token_type } = this.getToken() || {};
102+
103+
return token_type;
95104
}
96105

97106
/**

0 commit comments

Comments
 (0)