diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d6fa99..002ccf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,12 @@ ## Changelog +### 4.1.1 / 2017-04-03 +- [#118](https://github.com/oauthjs/angular-oauth2/pull/118) Validate object property access (@hitmanmcc) +- [#107](https://github.com/oauthjs/angular-oauth2/pull/107) Updated readme (@anteriovieira) + ### 4.1.0 / 2016-11-03 - [#87](https://github.com/oauthjs/angular-oauth2/pull/87) allow overriding oauth base config using options (@lionelB) +- [#96](https://github.com/oauthjs/angular-oauth2/pull/96) Specify the type of grant used (#96) (@Timokasse) ### 4.0.0 / 2016-02-12 - [#80](https://github.com/oauthjs/angular-oauth2/pull/80) Reintroduce authorization header to be overridden (@ruipenso) @@ -37,7 +42,7 @@ ### 2.0.0 / 2015-02-04 - [#11](https://github.com/oauthjs/angular-oauth2/pull/11) Add options to `ipCookie.remove()` on OAuthToken (@ruipenso) - [#10](https://github.com/oauthjs/angular-oauth2/pull/10) Update `oauthInterceptor` responseError handling (@ruipenso) -- [#7](https://github.com/oauthjs/angular-oauth2/pull/7) Fix readme typo of download url (@brunnolou) +- [#7](https://github.com/oauthjs/angular-oauth2/pull/7) Fix readme typo of download url (@seegno) - [#6](https://github.com/oauthjs/angular-oauth2/pull/6) README.md: typo fix (@AdirAmsalem) ### 1.0.2 / 2015-01-19 diff --git a/bower.json b/bower.json index c351c6e..137280d 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-oauth2", - "version": "4.0.0", + "version": "4.1.1", "description": "AngularJS OAuth2", "main": "./dist/angular-oauth2.js", "authors": [ @@ -23,8 +23,8 @@ "test" ], "dependencies": { - "angular": "^1.4.0", - "angular-cookies": "^1.4.0", + "angular": "1.5.9", + "angular-cookies": "1.5.9", "query-string": "^1.0.0" } } diff --git a/dist/angular-oauth2.js b/dist/angular-oauth2.js index 91122c9..ab9f75a 100644 --- a/dist/angular-oauth2.js +++ b/dist/angular-oauth2.js @@ -1,6 +1,6 @@ /** * angular-oauth2 - Angular OAuth2 - * @version v4.1.0 + * @version v4.1.1 * @link https://github.com/seegno/angular-oauth2 * @license MIT */ @@ -14,6 +14,10 @@ } })(this, function(angular, ngCookies, queryString) { var ngModule = angular.module("angular-oauth2", [ ngCookies ]).config(oauthConfig).factory("oauthInterceptor", oauthInterceptor).provider("OAuth", OAuthProvider).provider("OAuthToken", OAuthTokenProvider); + function oauthConfig($httpProvider) { + $httpProvider.interceptors.push("oauthInterceptor"); + } + oauthConfig.$inject = [ "$httpProvider" ]; function oauthInterceptor($q, $rootScope, OAuthToken) { return { request: function request(config) { @@ -24,11 +28,14 @@ return config; }, responseError: function responseError(rejection) { + if (!rejection) { + return $q.reject(rejection); + } if (400 === rejection.status && rejection.data && ("invalid_request" === rejection.data.error || "invalid_grant" === rejection.data.error)) { OAuthToken.removeToken(); $rootScope.$emit("oauth:error", rejection); } - if (401 === rejection.status && rejection.data && "invalid_token" === rejection.data.error || rejection.headers("www-authenticate") && 0 === rejection.headers("www-authenticate").indexOf("Bearer")) { + if (401 === rejection.status && rejection.data && "invalid_token" === rejection.data.error || rejection.headers && rejection.headers("www-authenticate") && 0 === rejection.headers("www-authenticate").indexOf("Bearer")) { $rootScope.$emit("oauth:error", rejection); } return $q.reject(rejection); @@ -36,10 +43,6 @@ }; } oauthInterceptor.$inject = [ "$q", "$rootScope", "OAuthToken" ]; - function oauthConfig($httpProvider) { - $httpProvider.interceptors.push("oauthInterceptor"); - } - oauthConfig.$inject = [ "$httpProvider" ]; var _createClass = function() { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { @@ -239,25 +242,33 @@ }, { key: "getAccessToken", value: function getAccessToken() { - return this.getToken() ? this.getToken().access_token : undefined; + var _ref = this.getToken() || {}; + var access_token = _ref.access_token; + return access_token; } }, { key: "getAuthorizationHeader", value: function getAuthorizationHeader() { - if (!(this.getTokenType() && this.getAccessToken())) { + var tokenType = this.getTokenType(); + var accessToken = this.getAccessToken(); + if (!tokenType || !accessToken) { return; } - return this.getTokenType().charAt(0).toUpperCase() + this.getTokenType().substr(1) + " " + this.getAccessToken(); + return tokenType.charAt(0).toUpperCase() + tokenType.substr(1) + " " + accessToken; } }, { key: "getRefreshToken", value: function getRefreshToken() { - return this.getToken() ? this.getToken().refresh_token : undefined; + var _ref2 = this.getToken() || {}; + var refresh_token = _ref2.refresh_token; + return refresh_token; } }, { key: "getTokenType", value: function getTokenType() { - return this.getToken() ? this.getToken().token_type : undefined; + var _ref3 = this.getToken() || {}; + var token_type = _ref3.token_type; + return token_type; } }, { key: "removeToken", diff --git a/dist/angular-oauth2.min.js b/dist/angular-oauth2.min.js index 98e09a3..b5ecefe 100644 --- a/dist/angular-oauth2.min.js +++ b/dist/angular-oauth2.min.js @@ -1 +1 @@ -!function(e,t){"function"==typeof define&&define.amd?define(["angular","angular-cookies","query-string"],t):"object"==typeof exports?module.exports=t(require("angular"),require("angular-cookies"),require("query-string")):e.angularOAuth2=t(e.angular,"ngCookies",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,r=function(t){if(!(t instanceof Object))throw new TypeError("Invalid argument: `config` must be an `Object`.");var n=e.extend({},f,t);return e.forEach(h,function(e){if(!n[e])throw new Error("Missing parameter: "+e+".")}),"/"===n.baseUrl.substr(-1)&&(n.baseUrl=n.baseUrl.slice(0,-1)),"/"!==n.grantPath[0]&&(n.grantPath="/"+n.grantPath),"/"!==n.revokePath[0]&&(n.revokePath="/"+n.revokePath),n};this.configure=function(e){t.defaultConfig=r(e)},this.$get=function(t,o){var a=function(){function a(e){i(this,a),this.config=e}return s(a,[{key:"configure",value:function(e){this.config=r(e)}},{key:"isAuthenticated",value:function(){return!!o.getToken()}},{key:"getAccessToken",value:function(r,i){return r=e.extend({client_id:this.config.clientId,grant_type:"password"},r),null!==this.config.clientSecret&&(r.client_secret=this.config.clientSecret),r=n.stringify(r),i=e.extend({headers:{Authorization:void 0,"Content-Type":"application/x-www-form-urlencoded"}},i),t.post(""+this.config.baseUrl+this.config.grantPath,r,i).then(function(e){return o.setToken(e.data),e})}},{key:"getRefreshToken",value:function(r,i){return r=e.extend({client_id:this.config.clientId,grant_type:"refresh_token",refresh_token:o.getRefreshToken()},r),null!==this.config.clientSecret&&(r.client_secret=this.config.clientSecret),r=n.stringify(r),i=e.extend({headers:{Authorization:void 0,"Content-Type":"application/x-www-form-urlencoded"}},i),t.post(""+this.config.baseUrl+this.config.grantPath,r,i).then(function(e){return o.setToken(e.data),e})}},{key:"revokeToken",value:function(r,i){var a=o.getRefreshToken();return r=e.extend({client_id:this.config.clientId,token:a?a:o.getAccessToken(),token_type_hint:a?"refresh_token":"access_token"},r),null!==this.config.clientSecret&&(r.client_secret=this.config.clientSecret),r=n.stringify(r),i=e.extend({headers:{"Content-Type":"application/x-www-form-urlencoded"}},i),t.post(""+this.config.baseUrl+this.config.revokePath,r,i).then(function(e){return o.removeToken(),e})}}]),a}();return new a(this.defaultConfig)},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.putObject(t.name,n,t.options)}},{key:"getToken",value:function(){return e.getObject(t.name)}},{key:"getAccessToken",value:function(){return this.getToken()?this.getToken().access_token:void 0}},{key:"getAuthorizationHeader",value:function(){if(this.getTokenType()&&this.getAccessToken())return this.getTokenType().charAt(0).toUpperCase()+this.getTokenType().substr(1)+" "+this.getAccessToken()}},{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=["$cookies"]}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