1
1
/**
2
2
* angular-oauth2 - Angular OAuth2
3
- * @version v3.0.0
3
+ * @version v3.0.1
4
4
* @link https://github.com/seegno/angular-oauth2
5
5
* @license MIT
6
6
*/
18
18
$httpProvider . interceptors . push ( "oauthInterceptor" ) ;
19
19
}
20
20
oauthConfig . $inject = [ "$httpProvider" ] ;
21
- function oauthInterceptor ( $q , $rootScope , OAuthToken ) {
22
- return {
23
- request : function ( config ) {
24
- if ( OAuthToken . getAuthorizationHeader ( ) ) {
25
- config . headers = config . headers || { } ;
26
- config . headers . Authorization = OAuthToken . getAuthorizationHeader ( ) ;
27
- }
28
- return config ;
29
- } ,
30
- responseError : function ( rejection ) {
31
- if ( 400 === rejection . status && rejection . data && ( "invalid_request" === rejection . data . error || "invalid_grant" === rejection . data . error ) ) {
32
- OAuthToken . removeToken ( ) ;
33
- $rootScope . $emit ( "oauth:error" , rejection ) ;
34
- }
35
- if ( 401 === rejection . status && ( rejection . data && "invalid_token" === rejection . data . error ) || rejection . headers ( "www-authenticate" ) && 0 === rejection . headers ( "www-authenticate" ) . indexOf ( "Bearer" ) ) {
36
- $rootScope . $emit ( "oauth:error" , rejection ) ;
37
- }
38
- return $q . reject ( rejection ) ;
39
- }
40
- } ;
41
- }
42
- oauthInterceptor . $inject = [ "$q" , "$rootScope" , "OAuthToken" ] ;
43
21
var _prototypeProperties = function ( child , staticProps , instanceProps ) {
44
22
if ( staticProps ) Object . defineProperties ( child , staticProps ) ;
45
23
if ( instanceProps ) Object . defineProperties ( child . prototype , instanceProps ) ;
262
240
} ;
263
241
this . $get . $inject = [ "$cookies" ] ;
264
242
}
243
+ function oauthInterceptor ( $q , $rootScope , OAuthToken ) {
244
+ return {
245
+ request : function ( config ) {
246
+ if ( OAuthToken . getAuthorizationHeader ( ) ) {
247
+ config . headers = config . headers || { } ;
248
+ config . headers . Authorization = OAuthToken . getAuthorizationHeader ( ) ;
249
+ }
250
+ return config ;
251
+ } ,
252
+ responseError : function ( rejection ) {
253
+ if ( 400 === rejection . status && rejection . data && ( "invalid_request" === rejection . data . error || "invalid_grant" === rejection . data . error ) ) {
254
+ OAuthToken . removeToken ( ) ;
255
+ $rootScope . $emit ( "oauth:error" , rejection ) ;
256
+ }
257
+ if ( 401 === rejection . status && ( rejection . data && "invalid_token" === rejection . data . error ) || rejection . headers ( "www-authenticate" ) && 0 === rejection . headers ( "www-authenticate" ) . indexOf ( "Bearer" ) ) {
258
+ $rootScope . $emit ( "oauth:error" , rejection ) ;
259
+ }
260
+ return $q . reject ( rejection ) ;
261
+ }
262
+ } ;
263
+ }
264
+ oauthInterceptor . $inject = [ "$q" , "$rootScope" , "OAuthToken" ] ;
265
265
return ngModule ;
266
266
} ) ;
0 commit comments