11/**
22 * angular-oauth2 - Angular OAuth2
3- * @version v2.1.1
3+ * @version v3.0.0
44 * @link https://github.com/seegno/angular-oauth2
55 * @license MIT
66 */
1313 root . angularOAuth2 = factory ( root . angular , root . queryString ) ;
1414 }
1515} ) ( 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 ) ;
1717 function oauthConfig ( $httpProvider ) {
1818 $httpProvider . interceptors . push ( "oauthInterceptor" ) ;
1919 }
3232 OAuthToken . removeToken ( ) ;
3333 $rootScope . $emit ( "oauth:error" , rejection ) ;
3434 }
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" ) ) {
3636 $rootScope . $emit ( "oauth:error" , rejection ) ;
3737 }
3838 return $q . reject ( rejection ) ;
8888 _prototypeProperties ( OAuth , null , {
8989 isAuthenticated : {
9090 value : function isAuthenticated ( ) {
91- return ! ! OAuthToken . token ;
91+ return ! ! OAuthToken . getToken ( ) ;
9292 } ,
9393 writable : true ,
9494 enumerable : true ,
115115 }
116116 } , options ) ;
117117 return $http . post ( "" + config . baseUrl + "" + config . grantPath , data , options ) . then ( function ( response ) {
118- OAuthToken . token = response . data ;
118+ OAuthToken . setToken ( response . data ) ;
119119 return response ;
120120 } ) ;
121121 } ,
140140 }
141141 } ;
142142 return $http . post ( "" + config . baseUrl + "" + config . grantPath , data , options ) . then ( function ( response ) {
143- OAuthToken . token = response . data ;
143+ OAuthToken . setToken ( response . data ) ;
144144 return response ;
145145 } ) ;
146146 } ,
192192 angular . extend ( config , params ) ;
193193 return config ;
194194 } ;
195- this . $get = function ( ipCookie ) {
195+ this . $get = function ( $cookies ) {
196196 var OAuthToken = function ( ) {
197197 function OAuthToken ( ) { }
198198 _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 ) ;
202202 } ,
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 ) ;
205210 } ,
211+ writable : true ,
206212 enumerable : true ,
207213 configurable : true
208214 } ,
209215 getAccessToken : {
210216 value : function getAccessToken ( ) {
211- return this . token ? this . token . access_token : undefined ;
217+ return this . getToken ( ) ? this . getToken ( ) . access_token : undefined ;
212218 } ,
213219 writable : true ,
214220 enumerable : true ,
227233 } ,
228234 getRefreshToken : {
229235 value : function getRefreshToken ( ) {
230- return this . token ? this . token . refresh_token : undefined ;
236+ return this . getToken ( ) ? this . getToken ( ) . refresh_token : undefined ;
231237 } ,
232238 writable : true ,
233239 enumerable : true ,
234240 configurable : true
235241 } ,
236242 getTokenType : {
237243 value : function getTokenType ( ) {
238- return this . token ? this . token . token_type : undefined ;
244+ return this . getToken ( ) ? this . getToken ( ) . token_type : undefined ;
239245 } ,
240246 writable : true ,
241247 enumerable : true ,
242248 configurable : true
243249 } ,
244250 removeToken : {
245251 value : function removeToken ( ) {
246- return ipCookie . remove ( config . name , angular . copy ( config . options ) ) ;
252+ return $cookies . remove ( config . name , config . options ) ;
247253 } ,
248254 writable : true ,
249255 enumerable : true ,
254260 } ( ) ;
255261 return new OAuthToken ( ) ;
256262 } ;
257- this . $get . $inject = [ "ipCookie " ] ;
263+ this . $get . $inject = [ "$cookies " ] ;
258264 }
259265 return ngModule ;
260266} ) ;
0 commit comments