!function(e,t){"function"==typeof define&&define.amd?define(["angular","angular-local-storage","query-string"],t):"object"==typeof exports?module.exports=t(require("angular"),require("angular-local-storage"),require("query-string")):e.angularOAuth2=t(e.angular,e.localStorageModule,e.queryString)}(this,function(e,t,n){function r(e,t,n){return{request:function(e){return e.headers=e.headers||{},!e.headers.hasOwnProperty("Authorization")&&n.getAuthorizationHeader()&&(e.headers.Authorization=n.getAuthorizationHeader()),e},responseError:function(r){return 400!==r.status||!r.data||"invalid_request"!==r.data.error&&"invalid_grant"!==r.data.error||(n.removeToken(),t.$emit("oauth:error",r)),(401===r.status&&r.data&&"invalid_token"===r.data.error||r.headers("www-authenticate")&&0===r.headers("www-authenticate").indexOf("Bearer"))&&t.$emit("oauth:error",r),e.reject(r)}}}function o(e){e.interceptors.push("oauthInterceptor")}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(){var t;this.configure=function(n){if(t)throw new Error("Already configured.");if(!(n instanceof Object))throw new TypeError("Invalid argument: `config` must be an `Object`.");return t=e.extend({},l,n),e.forEach(h,function(e){if(!t[e])throw new Error("Missing parameter: "+e+".")}),"/"===t.baseUrl.substr(-1)&&(t.baseUrl=t.baseUrl.slice(0,-1)),"/"!==t.grantPath[0]&&(t.grantPath="/"+t.grantPath),"/"!==t.revokePath[0]&&(t.revokePath="/"+t.revokePath),t},this.$get=function(r,o){var a=function(){function a(){if(i(this,a),!t)throw new Error("`OAuthProvider` must be configured first.")}return s(a,[{key:"isAuthenticated",value:function(){return!!o.getToken()}},{key:"getAccessToken",value:function(i,a){return i=e.extend({client_id:t.clientId,grant_type:"password"},i),null!==t.clientSecret&&(i.client_secret=t.clientSecret),i=n.stringify(i),a=e.extend({headers:{Authorization:void 0,"Content-Type":"application/x-www-form-urlencoded"}},a),r.post(""+t.baseUrl+t.grantPath,i,a).then(function(e){return o.setToken(e.data),e})}},{key:"getRefreshToken",value:function(i,a){return i=e.extend({client_id:t.clientId,grant_type:"refresh_token",refresh_token:o.getRefreshToken()},i),null!==t.clientSecret&&(i.client_secret=t.clientSecret),i=n.stringify(i),a=e.extend({headers:{Authorization:void 0,"Content-Type":"application/x-www-form-urlencoded"}},a),r.post(""+t.baseUrl+t.grantPath,i,a).then(function(e){return o.setToken(e.data),e})}},{key:"revokeToken",value:function(i,a){var u=o.getRefreshToken();return i=e.extend({client_id:t.clientId,token:u?u:o.getAccessToken(),token_type_hint:u?"refresh_token":"access_token"},i),null!==t.clientSecret&&(i.client_secret=t.clientSecret),i=n.stringify(i),a=e.extend({headers:{"Content-Type":"application/x-www-form-urlencoded"}},a),r.post(""+t.baseUrl+t.revokePath,i,a).then(function(e){return o.removeToken(),e})}}]),a}();return new a},this.$get.$inject=["$http","OAuthToken"]}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(){var t={name:"token",options:{secure:!0}};this.configure=function(n){if(!(n instanceof Object))throw new TypeError("Invalid argument: `config` must be an `Object`.");return e.extend(t,n),t},this.$get=function(e){var n=function(){function n(){i(this,n)}return s(n,[{key:"setToken",value:function(n){return e.set(t.name,n,t.options)}},{key:"getToken",value:function(){return e.get(t.name)}},{key:"getAccessToken",value:function(){return this.getToken()?this.getToken().access_token:void 0}},{key:"getAuthorizationHeader",value:function(){return this.getTokenType()&&this.getAccessToken()?this.getTokenType().charAt(0).toUpperCase()+this.getTokenType().substr(1)+" "+this.getAccessToken():void 0}},{key:"getRefreshToken",value:function(){return this.getToken()?this.getToken().refresh_token:void 0}},{key:"getTokenType",value:function(){return this.getToken()?this.getToken().token_type:void 0}},{key:"removeToken",value:function(){return e.remove(t.name,t.options)}}]),n}();return new n},this.$get.$inject=["localStorageService"]}var c=e.module("angular-oauth2",[t]).config(o).factory("oauthInterceptor",r).provider("OAuth",a).provider("OAuthToken",u);r.$inject=["$q","$rootScope","OAuthToken"],o.$inject=["$httpProvider"];var s=function(){function e(e,t){for(var n=0;n