11/**
22 * angular-oauth2 - Angular OAuth2
3- * @version v3.0.0
3+ * @version v3.0.1
44 * @link https://github.com/seegno/angular-oauth2
55 * @license MIT
66 */
1818 $httpProvider . interceptors . push ( "oauthInterceptor" ) ;
1919 }
2020 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" ] ;
4321 var _prototypeProperties = function ( child , staticProps , instanceProps ) {
4422 if ( staticProps ) Object . defineProperties ( child , staticProps ) ;
4523 if ( instanceProps ) Object . defineProperties ( child . prototype , instanceProps ) ;
262240 } ;
263241 this . $get . $inject = [ "$cookies" ] ;
264242 }
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" ] ;
265265 return ngModule ;
266266} ) ;
0 commit comments