Skip to content

Commit

Permalink
inject for use with storage method
Browse files Browse the repository at this point in the history
  • Loading branch information
jarbitlira committed Sep 9, 2015
1 parent e292698 commit 31d1a94
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Configuration defaults:
```js
OAuthTokenProvider.configure({
name: 'token',
storage:'cookies' // options: 'cookies','localstorage','sessionstorage'
storage:'cookies' // options: 'cookies', 'localstorage', 'sessionstorage'
options: {
secure: true
}
Expand Down
20 changes: 10 additions & 10 deletions dist/angular-oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
}
})(this, function(angular, queryString) {
var ngModule = angular.module("angular-oauth2", [ "ipCookie" ]).config(oauthConfig).factory("oauthInterceptor", oauthInterceptor).provider("OAuth", OAuthProvider).provider("OAuthToken", OAuthTokenProvider);
function oauthConfig($httpProvider) {
$httpProvider.interceptors.push("oauthInterceptor");
}
oauthConfig.$inject = [ "$httpProvider" ];
function oauthInterceptor($q, $rootScope, OAuthToken) {
return {
request: function(config) {
Expand All @@ -36,10 +40,6 @@
};
}
oauthInterceptor.$inject = [ "$q", "$rootScope", "OAuthToken" ];
function oauthConfig($httpProvider) {
$httpProvider.interceptors.push("oauthInterceptor");
}
oauthConfig.$inject = [ "$httpProvider" ];
var _prototypeProperties = function(child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
Expand Down Expand Up @@ -194,7 +194,7 @@
angular.extend(config, params);
return config;
};
this.$get = function(ipCookie) {
this.$get = function(ipCookie, $window) {
var OAuthToken = function() {
function OAuthToken() {}
_prototypeProperties(OAuthToken, null, {
Expand Down Expand Up @@ -269,10 +269,10 @@
return ipCookie(config.name, data, config.options);

case "localstorage":
return localStorage.setItem(config.name, angular.toJson(data));
return $window.localStorage.setItem(config.name, angular.toJson(data));

case "sessionstorage":
return localStorage.setItem(config.name, angular.toJson(data));
return $window.sessionStorage.setItem(config.name, angular.toJson(data));

default:
return ipCookie(config.name, data, config.options);
Expand All @@ -285,10 +285,10 @@
return ipCookie(config.name);

case "localstorage":
return angular.fromJson(localStorage.getItem(config.name));
return angular.fromJson($window.localStorage.getItem(config.name));

case "sessionstorage":
return angular.fromJson(sessionStorage.getItem(config.name));
return angular.fromJson($window.sessionStorage.getItem(config.name));

default:
return ipCookie(config.name);
Expand All @@ -312,7 +312,7 @@
};
return new OAuthToken();
};
this.$get.$inject = [ "ipCookie" ];
this.$get.$inject = [ "ipCookie", "$window" ];
}
return ngModule;
});
2 changes: 1 addition & 1 deletion dist/angular-oauth2.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/providers/oauth-token-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function OAuthTokenProvider() {
* @ngInject
*/

this.$get = function(ipCookie) {
this.$get = function(ipCookie, $window) {
class OAuthToken {

/**
Expand Down Expand Up @@ -121,9 +121,9 @@ function OAuthTokenProvider() {
case 'cookies':
return ipCookie(config.name, data, config.options);
case 'localstorage':
return localStorage.setItem(config.name, angular.toJson(data));
return $window.localStorage.setItem(config.name, angular.toJson(data));
case 'sessionstorage':
return localStorage.setItem(config.name, angular.toJson(data));
return $window.sessionStorage.setItem(config.name, angular.toJson(data));
default :
return ipCookie(config.name, data, config.options);
}
Expand All @@ -140,9 +140,9 @@ function OAuthTokenProvider() {
case 'cookies':
return ipCookie(config.name);
case 'localstorage':
return angular.fromJson(localStorage.getItem(config.name));
return angular.fromJson($window.localStorage.getItem(config.name));
case 'sessionstorage':
return angular.fromJson(sessionStorage.getItem(config.name));
return angular.fromJson($window.sessionStorage.getItem(config.name));
default :
return ipCookie(config.name);
}
Expand Down

0 comments on commit 31d1a94

Please sign in to comment.