13
13
root . angularOAuth2 = factory ( root . angular , root . queryString ) ;
14
14
}
15
15
} ) ( this , function ( angular , queryString ) {
16
- var ngModule = angular . module ( "angular-oauth2" , [ "ngStorage " , "ngCookies " ] ) . config ( oauthConfig ) . factory ( "oauthInterceptor" , oauthInterceptor ) . provider ( "OAuth" , OAuthProvider ) . provider ( "OAuthToken" , OAuthTokenProvider ) . service ( "OAuthStorage" , OAuthStorageProvider ) ;
16
+ var ngModule = angular . module ( "angular-oauth2" , [ "ngCookies " , "ngStorage " ] ) . config ( oauthConfig ) . factory ( "oauthInterceptor" , oauthInterceptor ) . provider ( "OAuth" , OAuthProvider ) . provider ( "OAuthToken" , OAuthTokenProvider ) . provider ( "OAuthStorage" , OAuthStorageProvider ) ;
17
17
function oauthConfig ( $httpProvider ) {
18
18
$httpProvider . interceptors . push ( "oauthInterceptor" ) ;
19
19
}
178
178
if ( staticProps ) Object . defineProperties ( child , staticProps ) ;
179
179
if ( instanceProps ) Object . defineProperties ( child . prototype , instanceProps ) ;
180
180
} ;
181
- function OAuthTokenProvider ( ) {
181
+ function OAuthTokenProvider ( $injector ) {
182
182
var config = {
183
183
name : "token" ,
184
184
storage : "cookies" ,
191
191
throw new TypeError ( "Invalid argument: `config` must be an `Object`." ) ;
192
192
}
193
193
angular . extend ( config , params ) ;
194
+ $injector . invoke ( function ( OAuthStorageProvider ) {
195
+ OAuthStorageProvider . configure ( config ) ;
196
+ } ) ;
194
197
return config ;
195
198
} ;
196
199
this . $get = function ( OAuthStorage ) {
197
200
var OAuthToken = function ( ) {
198
- function OAuthToken ( ) {
199
- console . log ( OAuthStorage ) ;
200
- }
201
+ function OAuthToken ( ) { }
201
202
_prototypeProperties ( OAuthToken , null , {
202
- token : {
203
- set : function ( data ) {
203
+ setToken : {
204
+ value : function setToken ( data ) {
204
205
return OAuthStorage . setToken ( data ) ;
205
206
} ,
206
- get : function ( ) {
207
+ writable : true ,
208
+ enumerable : true ,
209
+ configurable : true
210
+ } ,
211
+ getToken : {
212
+ value : function getToken ( ) {
207
213
return OAuthStorage . getToken ( ) ;
208
214
} ,
215
+ writable : true ,
209
216
enumerable : true ,
210
217
configurable : true
211
218
} ,
264
271
if ( instanceProps ) Object . defineProperties ( child . prototype , instanceProps ) ;
265
272
} ;
266
273
function OAuthStorageProvider ( ) {
267
- var config = { } ;
274
+ var config = {
275
+ name : "token" ,
276
+ storage : "cookies" ,
277
+ options : {
278
+ secure : true
279
+ }
280
+ } ;
268
281
this . configure = function ( params ) {
269
282
angular . extend ( config , params ) ;
270
283
return config ;
271
284
} ;
272
- this . $get = [ "$localStorage" , "$sessionStorage" , "$cookies" , "$log" , function ( $localStorage , $sessionStorage , $cookies , $log ) {
285
+ this . $get = function ( $localStorage , $sessionStorage , $cookies , $log ) {
273
286
var storage ;
274
- var ngStorage = ( config . storage || "cookies" ) . toLowerCase ( ) ;
287
+ var ngStorage = config . storage . toLowerCase ( ) ;
275
288
if ( ngStorage === "localstorage" ) {
276
289
storage = $localStorage ;
277
290
} else if ( ngStorage === "sessionstorage" ) {
278
291
storage = $sessionStorage ;
279
292
} else if ( ngStorage === "cookies" ) {
280
293
storage = $cookies ;
281
294
} else {
295
+ storage = $cookies ;
282
296
$log . warn ( "Set storage to cookies, because storage type is unknown" ) ;
283
297
}
284
298
var BrowserStorage = function ( ) {
287
301
this . name = name ;
288
302
}
289
303
_prototypeProperties ( BrowserStorage , null , {
290
- token : {
291
- set : function ( data ) {
292
- return this . storage . setItem ( this . name , angular . toJson ( data ) ) ;
304
+ setToken : {
305
+ value : function setToken ( data ) {
306
+ return this . storage [ this . name ] = angular . toJson ( data ) ;
293
307
} ,
294
- get : function ( ) {
295
- return angular . fromJson ( this . storage . getItem ( this . name ) ) ;
308
+ writable : true ,
309
+ enumerable : true ,
310
+ configurable : true
311
+ } ,
312
+ getToken : {
313
+ value : function getToken ( ) {
314
+ return angular . fromJson ( this . storage [ this . name ] ) ;
296
315
} ,
316
+ writable : true ,
297
317
enumerable : true ,
298
318
configurable : true
299
319
} ,
315
335
this . options = options ;
316
336
}
317
337
_prototypeProperties ( CookieStorage , null , {
318
- token : {
319
- set : function ( value ) {
338
+ setToken : {
339
+ value : function setToken ( value ) {
320
340
return this . $cookies . putObject ( this . name , value , this . options ) ;
321
341
} ,
322
- get : function ( ) {
342
+ writable : true ,
343
+ enumerable : true ,
344
+ configurable : true
345
+ } ,
346
+ getToken : {
347
+ value : function getToken ( ) {
323
348
return this . $cookies . getObject ( this . name ) ;
324
349
} ,
350
+ writable : true ,
325
351
enumerable : true ,
326
352
configurable : true
327
353
} ,
337
363
return CookieStorage ;
338
364
} ( ) ;
339
365
var OAuthStorage = function ( ) {
340
- function OAuthStorage ( ) {
341
- this . storage = ngStorage === "cookies" ? new CookieStorage ( storage , config . name , config . options ) : new BrowserStorage ( storage , config . name ) ;
342
- $log . info ( "Storage Started" ) ;
366
+ function OAuthStorage ( storage ) {
367
+ this . storage = storage ;
343
368
}
344
369
_prototypeProperties ( OAuthStorage , null , {
345
- token : {
346
- set : function ( value ) {
370
+ setToken : {
371
+ value : function setToken ( value ) {
347
372
return this . storage . setToken ( value ) ;
348
373
} ,
349
- get : function ( ) {
374
+ writable : true ,
375
+ enumerable : true ,
376
+ configurable : true
377
+ } ,
378
+ getToken : {
379
+ value : function getToken ( ) {
350
380
return this . storage . getToken ( ) ;
351
381
} ,
382
+ writable : true ,
352
383
enumerable : true ,
353
384
configurable : true
354
385
} ,
363
394
} ) ;
364
395
return OAuthStorage ;
365
396
} ( ) ;
366
- return new OAuthStorage ( ) ;
367
- } ] ;
397
+ storage = ngStorage === "cookies" ? new CookieStorage ( storage , config . name , config . options ) : new BrowserStorage ( storage , config . name ) ;
398
+ return new OAuthStorage ( storage ) ;
399
+ } ;
400
+ this . $get . $inject = [ "$localStorage" , "$sessionStorage" , "$cookies" , "$log" ] ;
368
401
}
369
402
return ngModule ;
370
403
} ) ;
0 commit comments