Skip to content

Commit e292698

Browse files
committed
enhance code and refactor changes
1 parent d9bf178 commit e292698

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

dist/angular-oauth2.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
}
1515
})(this, function(angular, queryString) {
1616
var ngModule = angular.module("angular-oauth2", [ "ipCookie" ]).config(oauthConfig).factory("oauthInterceptor", oauthInterceptor).provider("OAuth", OAuthProvider).provider("OAuthToken", OAuthTokenProvider);
17-
function oauthConfig($httpProvider) {
18-
$httpProvider.interceptors.push("oauthInterceptor");
19-
}
20-
oauthConfig.$inject = [ "$httpProvider" ];
2117
function oauthInterceptor($q, $rootScope, OAuthToken) {
2218
return {
2319
request: function(config) {
@@ -40,6 +36,10 @@
4036
};
4137
}
4238
oauthInterceptor.$inject = [ "$q", "$rootScope", "OAuthToken" ];
39+
function oauthConfig($httpProvider) {
40+
$httpProvider.interceptors.push("oauthInterceptor");
41+
}
42+
oauthConfig.$inject = [ "$httpProvider" ];
4343
var _prototypeProperties = function(child, staticProps, instanceProps) {
4444
if (staticProps) Object.defineProperties(child, staticProps);
4545
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
@@ -269,10 +269,10 @@
269269
return ipCookie(config.name, data, config.options);
270270

271271
case "localstorage":
272-
return localStorage.setItem(config.name, JSON.stringify(data));
272+
return localStorage.setItem(config.name, angular.toJson(data));
273273

274274
case "sessionstorage":
275-
return sessionStorage.setItem(config.name, JSON.stringify(data));
275+
return localStorage.setItem(config.name, angular.toJson(data));
276276

277277
default:
278278
return ipCookie(config.name, data, config.options);
@@ -285,10 +285,10 @@
285285
return ipCookie(config.name);
286286

287287
case "localstorage":
288-
return JSON.parse(localStorage.getItem(config.name));
288+
return angular.fromJson(localStorage.getItem(config.name));
289289

290290
case "sessionstorage":
291-
return JSON.parse(sessionStorage.getItem(config.name));
291+
return angular.fromJson(sessionStorage.getItem(config.name));
292292

293293
default:
294294
return ipCookie(config.name);

dist/angular-oauth2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/providers/oauth-provider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ function OAuthProvider() {
167167
};
168168

169169
return $http.post(`${config.baseUrl}${config.grantPath}`, data, options).then((response) => {
170-
171170
OAuthToken.token = response.data;
171+
172172
return response;
173173
});
174174
}

src/providers/oauth-token-provider.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function OAuthTokenProvider() {
1313
var storage;
1414
var config = {
1515
name: 'token',
16-
storage: 'cookies',//cookies,localStorage,sessionStorage
16+
storage: 'cookies', //cookies,localStorage,sessionStorage
1717
options: {
1818
secure: true
1919
}
@@ -114,15 +114,16 @@ function OAuthTokenProvider() {
114114
* @param data
115115
* @returns {*}
116116
*/
117+
117118
var setToken = function(data) {
118119
storage = config.storage.toLowerCase();
119120
switch (storage) {
120121
case 'cookies':
121122
return ipCookie(config.name, data, config.options);
122123
case 'localstorage':
123-
return localStorage.setItem(config.name,JSON.stringify(data));
124+
return localStorage.setItem(config.name, angular.toJson(data));
124125
case 'sessionstorage':
125-
return sessionStorage.setItem(config.name,JSON.stringify(data));
126+
return localStorage.setItem(config.name, angular.toJson(data));
126127
default :
127128
return ipCookie(config.name, data, config.options);
128129
}
@@ -139,12 +140,11 @@ function OAuthTokenProvider() {
139140
case 'cookies':
140141
return ipCookie(config.name);
141142
case 'localstorage':
142-
return JSON.parse(localStorage.getItem(config.name));
143+
return angular.fromJson(localStorage.getItem(config.name));
143144
case 'sessionstorage':
144-
return JSON.parse(sessionStorage.getItem(config.name));
145+
return angular.fromJson(sessionStorage.getItem(config.name));
145146
default :
146147
return ipCookie(config.name);
147-
148148
}
149149
};
150150

0 commit comments

Comments
 (0)