13
13
root . angularOAuth2 = factory ( root . angular , root . queryString ) ;
14
14
}
15
15
} ) ( this , function ( angular , queryString ) {
16
- var ngModule = angular . module ( "angular-oauth2" , [ "ipCookie" ] ) . config ( oauthConfig ) . factory ( "oauthInterceptor" , oauthInterceptor ) . provider ( "OAuth" , OAuthProvider ) . provider ( "OAuthToken" , OAuthTokenProvider ) ;
16
+ var ngModule = angular . module ( "angular-oauth2" , [ "ngStorage" , "ngCookies" ] ) . config ( oauthConfig ) . factory ( "oauthInterceptor" , oauthInterceptor ) . provider ( "OAuth" , OAuthProvider ) . provider ( "OAuthToken" , OAuthTokenProvider ) . service ( "OAuthStorage" , OAuthStorageProvider ) ;
17
17
function oauthConfig ( $httpProvider ) {
18
18
$httpProvider . interceptors . push ( "oauthInterceptor" ) ;
19
19
}
179
179
if ( instanceProps ) Object . defineProperties ( child . prototype , instanceProps ) ;
180
180
} ;
181
181
function OAuthTokenProvider ( ) {
182
- var storage ;
183
182
var config = {
184
183
name : "token" ,
185
184
storage : "cookies" ,
194
193
angular . extend ( config , params ) ;
195
194
return config ;
196
195
} ;
197
- this . $get = function ( ipCookie , $window ) {
196
+ this . $get = function ( OAuthStorage ) {
198
197
var OAuthToken = function ( ) {
199
- function OAuthToken ( ) { }
198
+ function OAuthToken ( ) {
199
+ console . log ( OAuthStorage ) ;
200
+ }
200
201
_prototypeProperties ( OAuthToken , null , {
201
202
token : {
202
203
set : function ( data ) {
203
- return setToken ( data ) ;
204
+ return OAuthStorage . setToken ( data ) ;
204
205
} ,
205
206
get : function ( ) {
206
- return getToken ( ) ;
207
+ return OAuthStorage . getToken ( ) ;
207
208
} ,
208
209
enumerable : true ,
209
210
configurable : true
244
245
configurable : true
245
246
} ,
246
247
removeToken : {
247
- value : function ( _removeToken ) {
248
- var _removeTokenWrapper = function removeToken ( ) {
249
- return _removeToken . apply ( this , arguments ) ;
250
- } ;
251
- _removeTokenWrapper . toString = function ( ) {
252
- return _removeToken . toString ( ) ;
253
- } ;
254
- return _removeTokenWrapper ;
255
- } ( function ( ) {
256
- return removeToken ( ) ;
257
- } ) ,
248
+ value : function removeToken ( ) {
249
+ return OAuthStorage . removeToken ( ) ;
250
+ } ,
258
251
writable : true ,
259
252
enumerable : true ,
260
253
configurable : true
261
254
}
262
255
} ) ;
263
256
return OAuthToken ;
264
257
} ( ) ;
265
- var setToken = function ( data ) {
266
- storage = config . storage . toLowerCase ( ) ;
267
- switch ( storage ) {
268
- case "cookies" :
269
- return ipCookie ( config . name , data , config . options ) ;
270
-
271
- case "localstorage" :
272
- return $window . localStorage . setItem ( config . name , angular . toJson ( data ) ) ;
273
-
274
- case "sessionstorage" :
275
- return $window . sessionStorage . setItem ( config . name , angular . toJson ( data ) ) ;
276
-
277
- default :
278
- return ipCookie ( config . name , data , config . options ) ;
258
+ return new OAuthToken ( ) ;
259
+ } ;
260
+ this . $get . $inject = [ "OAuthStorage" ] ;
261
+ }
262
+ var _prototypeProperties = function ( child , staticProps , instanceProps ) {
263
+ if ( staticProps ) Object . defineProperties ( child , staticProps ) ;
264
+ if ( instanceProps ) Object . defineProperties ( child . prototype , instanceProps ) ;
265
+ } ;
266
+ function OAuthStorageProvider ( ) {
267
+ var config = { } ;
268
+ this . $get = [ "$localStorage" , "$sessionStorage" , "$cookies" , "$log" , function ( $localStorage , $sessionStorage , $cookies , $log ) {
269
+ var storage ;
270
+ var ngStorage = ( config . storage || "cookies" ) . toLowerCase ( ) ;
271
+ var BrowserStorage = function ( ) {
272
+ function BrowserStorage ( storage , name ) {
273
+ this . storage = storage ;
274
+ this . name = name ;
279
275
}
280
- } ;
281
- var getToken = function ( ) {
282
- storage = config . storage . toLowerCase ( ) ;
283
- switch ( storage ) {
284
- case "cookies" :
285
- return ipCookie ( config . name ) ;
286
-
287
- case "localstorage" :
288
- return angular . fromJson ( $window . localStorage . getItem ( config . name ) ) ;
289
-
290
- case "sessionstorage" :
291
- return angular . fromJson ( $window . sessionStorage . getItem ( config . name ) ) ;
292
-
293
- default :
294
- return ipCookie ( config . name ) ;
276
+ _prototypeProperties ( BrowserStorage , null , {
277
+ token : {
278
+ set : function ( data ) {
279
+ return this . storage . setItem ( this . name , angular . toJson ( data ) ) ;
280
+ } ,
281
+ get : function ( ) {
282
+ return angular . fromJson ( this . storage . getItem ( this . name ) ) ;
283
+ } ,
284
+ enumerable : true ,
285
+ configurable : true
286
+ } ,
287
+ deleteToken : {
288
+ value : function deleteToken ( ) {
289
+ this . storage . removeItem ( this . name ) ;
290
+ } ,
291
+ writable : true ,
292
+ enumerable : true ,
293
+ configurable : true
294
+ }
295
+ } ) ;
296
+ return BrowserStorage ;
297
+ } ( ) ;
298
+ var CookieStorage = function ( ) {
299
+ function CookieStorage ( $cookies , name , options ) {
300
+ this . $cookies = storage ;
301
+ this . name = name ;
302
+ this . options = options ;
295
303
}
296
- } ;
297
- var removeToken = function ( ) {
298
- storage = config . storage . toLowerCase ( ) ;
299
- switch ( storage ) {
300
- case "cookies" :
301
- return ipCookie . remove ( config . name , config . options ) ;
302
-
303
- case "localstorage" :
304
- return $window . localStorage . removeItem ( config . name ) ;
305
-
306
- case "sessionstorage" :
307
- return $window . sessionStorage . removeItem ( config . name ) ;
308
-
309
- default :
310
- return ipCookie . remove ( config . name , config . options ) ;
304
+ _prototypeProperties ( CookieStorage , null , {
305
+ token : {
306
+ set : function ( value ) {
307
+ return this . $cookies . putObject ( this . name , value , this . options ) ;
308
+ } ,
309
+ get : function ( ) {
310
+ return this . $cookies . getObject ( this . name ) ;
311
+ } ,
312
+ enumerable : true ,
313
+ configurable : true
314
+ } ,
315
+ deleteToken : {
316
+ value : function deleteToken ( ) {
317
+ return this . $cookies . remove ( this . name , this . options ) ;
318
+ } ,
319
+ writable : true ,
320
+ enumerable : true ,
321
+ configurable : true
322
+ }
323
+ } ) ;
324
+ return CookieStorage ;
325
+ } ( ) ;
326
+ var OAuthStorage = function ( ) {
327
+ function OAuthStorage ( ) {
328
+ this . storage = ngStorage === "cookies" ? new CookieStorage ( storage , config . name , config . options ) : new BrowserStorage ( storage , config . name ) ;
329
+ $log . info ( "Storage Started" ) ;
311
330
}
312
- } ;
313
- return new OAuthToken ( ) ;
314
- } ;
315
- this . $get . $inject = [ "ipCookie" , "$window" ] ;
331
+ _prototypeProperties ( OAuthStorage , null , {
332
+ token : {
333
+ set : function ( value ) {
334
+ return this . storage . setToken ( value ) ;
335
+ } ,
336
+ get : function ( ) {
337
+ return this . storage . getToken ( ) ;
338
+ } ,
339
+ enumerable : true ,
340
+ configurable : true
341
+ } ,
342
+ deleteToken : {
343
+ value : function deleteToken ( ) {
344
+ return this . storage . deleteToken ( ) ;
345
+ } ,
346
+ writable : true ,
347
+ enumerable : true ,
348
+ configurable : true
349
+ }
350
+ } ) ;
351
+ return OAuthStorage ;
352
+ } ( ) ;
353
+ return new OAuthStorage ( ) ;
354
+ } ] ;
316
355
}
317
356
return ngModule ;
318
357
} ) ;
0 commit comments