1
1
/**
2
2
* angular-oauth2 - Angular OAuth2
3
- * @version v2.1.1
3
+ * @version v3.0.0
4
4
* @link https://github.com/seegno/angular-oauth2
5
5
* @license MIT
6
6
*/
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" , [ "ngCookies " ] ) . config ( oauthConfig ) . factory ( "oauthInterceptor" , oauthInterceptor ) . provider ( "OAuth" , OAuthProvider ) . provider ( "OAuthToken" , OAuthTokenProvider ) ;
17
17
function oauthConfig ( $httpProvider ) {
18
18
$httpProvider . interceptors . push ( "oauthInterceptor" ) ;
19
19
}
32
32
OAuthToken . removeToken ( ) ;
33
33
$rootScope . $emit ( "oauth:error" , rejection ) ;
34
34
}
35
- if ( 401 === rejection . status && rejection . data && "invalid_token" === rejection . data . error ) {
35
+ if ( 401 === rejection . status && ( rejection . data && "invalid_token" === rejection . data . error ) || rejection . headers ( "www-authenticate" ) && 0 === rejection . headers ( "www-authenticate" ) . indexOf ( "Bearer" ) ) {
36
36
$rootScope . $emit ( "oauth:error" , rejection ) ;
37
37
}
38
38
return $q . reject ( rejection ) ;
88
88
_prototypeProperties ( OAuth , null , {
89
89
isAuthenticated : {
90
90
value : function isAuthenticated ( ) {
91
- return ! ! OAuthToken . token ;
91
+ return ! ! OAuthToken . getToken ( ) ;
92
92
} ,
93
93
writable : true ,
94
94
enumerable : true ,
115
115
}
116
116
} , options ) ;
117
117
return $http . post ( "" + config . baseUrl + "" + config . grantPath , data , options ) . then ( function ( response ) {
118
- OAuthToken . token = response . data ;
118
+ OAuthToken . setToken ( response . data ) ;
119
119
return response ;
120
120
} ) ;
121
121
} ,
140
140
}
141
141
} ;
142
142
return $http . post ( "" + config . baseUrl + "" + config . grantPath , data , options ) . then ( function ( response ) {
143
- OAuthToken . token = response . data ;
143
+ OAuthToken . setToken ( response . data ) ;
144
144
return response ;
145
145
} ) ;
146
146
} ,
192
192
angular . extend ( config , params ) ;
193
193
return config ;
194
194
} ;
195
- this . $get = function ( ipCookie ) {
195
+ this . $get = function ( $cookies ) {
196
196
var OAuthToken = function ( ) {
197
197
function OAuthToken ( ) { }
198
198
_prototypeProperties ( OAuthToken , null , {
199
- token : {
200
- set : function ( data ) {
201
- return ipCookie ( config . name , data , config . options ) ;
199
+ setToken : {
200
+ value : function setToken ( data ) {
201
+ return $cookies . putObject ( config . name , data , config . options ) ;
202
202
} ,
203
- get : function ( ) {
204
- return ipCookie ( config . name ) ;
203
+ writable : true ,
204
+ enumerable : true ,
205
+ configurable : true
206
+ } ,
207
+ getToken : {
208
+ value : function getToken ( ) {
209
+ return $cookies . getObject ( config . name ) ;
205
210
} ,
211
+ writable : true ,
206
212
enumerable : true ,
207
213
configurable : true
208
214
} ,
209
215
getAccessToken : {
210
216
value : function getAccessToken ( ) {
211
- return this . token ? this . token . access_token : undefined ;
217
+ return this . getToken ( ) ? this . getToken ( ) . access_token : undefined ;
212
218
} ,
213
219
writable : true ,
214
220
enumerable : true ,
227
233
} ,
228
234
getRefreshToken : {
229
235
value : function getRefreshToken ( ) {
230
- return this . token ? this . token . refresh_token : undefined ;
236
+ return this . getToken ( ) ? this . getToken ( ) . refresh_token : undefined ;
231
237
} ,
232
238
writable : true ,
233
239
enumerable : true ,
234
240
configurable : true
235
241
} ,
236
242
getTokenType : {
237
243
value : function getTokenType ( ) {
238
- return this . token ? this . token . token_type : undefined ;
244
+ return this . getToken ( ) ? this . getToken ( ) . token_type : undefined ;
239
245
} ,
240
246
writable : true ,
241
247
enumerable : true ,
242
248
configurable : true
243
249
} ,
244
250
removeToken : {
245
251
value : function removeToken ( ) {
246
- return ipCookie . remove ( config . name , angular . copy ( config . options ) ) ;
252
+ return $cookies . remove ( config . name , config . options ) ;
247
253
} ,
248
254
writable : true ,
249
255
enumerable : true ,
254
260
} ( ) ;
255
261
return new OAuthToken ( ) ;
256
262
} ;
257
- this . $get . $inject = [ "ipCookie " ] ;
263
+ this . $get . $inject = [ "$cookies " ] ;
258
264
}
259
265
return ngModule ;
260
266
} ) ;
0 commit comments