Skip to content

Commit df5abac

Browse files
committed
inject $window for use with storage method
1 parent e292698 commit df5abac

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Configuration defaults:
153153
```js
154154
OAuthTokenProvider.configure({
155155
name: 'token',
156-
storage:'cookies' // options: 'cookies','localstorage','sessionstorage'
156+
storage:'cookies' // options: 'cookies', 'localstorage', 'sessionstorage'
157157
options: {
158158
secure: true
159159
}

dist/angular-oauth2.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
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" ];
1721
function oauthInterceptor($q, $rootScope, OAuthToken) {
1822
return {
1923
request: function(config) {
@@ -36,10 +40,6 @@
3640
};
3741
}
3842
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);
@@ -194,7 +194,7 @@
194194
angular.extend(config, params);
195195
return config;
196196
};
197-
this.$get = function(ipCookie) {
197+
this.$get = function(ipCookie, $window) {
198198
var OAuthToken = function() {
199199
function OAuthToken() {}
200200
_prototypeProperties(OAuthToken, null, {
@@ -269,10 +269,10 @@
269269
return ipCookie(config.name, data, config.options);
270270

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

274274
case "sessionstorage":
275-
return localStorage.setItem(config.name, angular.toJson(data));
275+
return $window.sessionStorage.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 angular.fromJson(localStorage.getItem(config.name));
288+
return angular.fromJson($window.localStorage.getItem(config.name));
289289

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

293293
default:
294294
return ipCookie(config.name);
@@ -312,7 +312,7 @@
312312
};
313313
return new OAuthToken();
314314
};
315-
this.$get.$inject = [ "ipCookie" ];
315+
this.$get.$inject = [ "ipCookie", "$window" ];
316316
}
317317
return ngModule;
318318
});

dist/angular-oauth2.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/providers/oauth-token-provider.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function OAuthTokenProvider() {
4343
* @ngInject
4444
*/
4545

46-
this.$get = function(ipCookie) {
46+
this.$get = function(ipCookie, $window) {
4747
class OAuthToken {
4848

4949
/**
@@ -121,9 +121,9 @@ function OAuthTokenProvider() {
121121
case 'cookies':
122122
return ipCookie(config.name, data, config.options);
123123
case 'localstorage':
124-
return localStorage.setItem(config.name, angular.toJson(data));
124+
return $window.localStorage.setItem(config.name, angular.toJson(data));
125125
case 'sessionstorage':
126-
return localStorage.setItem(config.name, angular.toJson(data));
126+
return $window.sessionStorage.setItem(config.name, angular.toJson(data));
127127
default :
128128
return ipCookie(config.name, data, config.options);
129129
}
@@ -140,9 +140,9 @@ function OAuthTokenProvider() {
140140
case 'cookies':
141141
return ipCookie(config.name);
142142
case 'localstorage':
143-
return angular.fromJson(localStorage.getItem(config.name));
143+
return angular.fromJson($window.localStorage.getItem(config.name));
144144
case 'sessionstorage':
145-
return angular.fromJson(sessionStorage.getItem(config.name));
145+
return angular.fromJson($window.sessionStorage.getItem(config.name));
146146
default :
147147
return ipCookie(config.name);
148148
}

0 commit comments

Comments
 (0)