Skip to content

Commit 46ebcf5

Browse files
committed
Release 3.1.0
1 parent 5c21efa commit 46ebcf5

File tree

5 files changed

+63
-52
lines changed

5 files changed

+63
-52
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## Changelog
22

3+
### upcoming / 2016-02-10
4+
- [#78](https://github.com/seegno/angular-oauth2/pull/78) Update OAuth methods to allow `data` and `options` override (@ruipenso)
5+
- [#71](https://github.com/seegno/angular-oauth2/pull/71) Add `client_id` and `client_secret` on revoke_token (@tinogomes)
6+
- [#77](https://github.com/seegno/angular-oauth2/pull/77) Update interceptor to allow authorization header to be overridden (@ruipenso)
7+
- [#75](https://github.com/seegno/angular-oauth2/pull/75) Update README dependencies (@ruipenso)
8+
- [#76](https://github.com/seegno/angular-oauth2/pull/76) Update `package.json` (@ruipenso)
9+
310
### 3.0.1 / 2015-06-01
411
- [#27](https://github.com/seegno/angular-oauth2/pull/27) Add travis-ci configuration (@joaogranado)
512

@@ -32,4 +39,4 @@
3239

3340
### 1.0.0 / 2015-01-18
3441
- [#2](https://github.com/seegno/angular-oauth2/pull/2) Fix indentation in README examples (@fixe)
35-
- [#1](https://github.com/seegno/angular-oauth2/pull/1) Add project structure (@ruipenso)
42+
- [#1](https://github.com/seegno/angular-oauth2/pull/1) Add project structure (@ruipenso)

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-oauth2",
3-
"version": "3.0.1",
3+
"version": "3.1.0",
44
"description": "AngularJS OAuth2",
55
"main": "./dist/angular-oauth2.js",
66
"authors": [

dist/angular-oauth2.js

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
11
/**
22
* angular-oauth2 - Angular OAuth2
3-
* @version v3.0.1
3+
* @version v3.1.0
44
* @link https://github.com/seegno/angular-oauth2
55
* @license MIT
66
*/
77
(function(root, factory) {
88
if (typeof define === "function" && define.amd) {
9-
define([ "angular", "query-string" ], factory);
9+
define([ "angular", "angular-cookies", "query-string" ], factory);
1010
} else if (typeof exports === "object") {
11-
module.exports = factory(require("angular"), require("query-string"));
11+
module.exports = factory(require("angular"), require("angular-cookies"), require("query-string"));
1212
} else {
13-
root.angularOAuth2 = factory(root.angular, root.queryString);
13+
root.angularOAuth2 = factory(root.angular, "ngCookies", root.queryString);
1414
}
15-
})(this, function(angular, queryString) {
16-
var ngModule = angular.module("angular-oauth2", [ "ngCookies" ]).config(oauthConfig).factory("oauthInterceptor", oauthInterceptor).provider("OAuth", OAuthProvider).provider("OAuthToken", OAuthTokenProvider);
15+
})(this, function(angular, ngCookies, queryString) {
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
}
2020
oauthConfig.$inject = [ "$httpProvider" ];
21+
function oauthInterceptor($q, $rootScope, OAuthToken) {
22+
return {
23+
request: function(config) {
24+
config.headers = config.headers || {};
25+
if (!config.headers.hasOwnProperty("Authorization") && OAuthToken.getAuthorizationHeader()) {
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" ];
2143
var _prototypeProperties = function(child, staticProps, instanceProps) {
2244
if (staticProps) Object.defineProperties(child, staticProps);
2345
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
@@ -73,22 +95,18 @@
7395
configurable: true
7496
},
7597
getAccessToken: {
76-
value: function getAccessToken(user, options) {
77-
if (!user || !user.username || !user.password) {
78-
throw new Error("`user` must be an object with `username` and `password` properties.");
79-
}
80-
var data = {
98+
value: function getAccessToken(data, options) {
99+
data = angular.extend({
81100
client_id: config.clientId,
82-
grant_type: "password",
83-
username: user.username,
84-
password: user.password
85-
};
101+
grant_type: "password"
102+
}, data);
86103
if (null !== config.clientSecret) {
87104
data.client_secret = config.clientSecret;
88105
}
89106
data = queryString.stringify(data);
90107
options = angular.extend({
91108
headers: {
109+
Authorization: undefined,
92110
"Content-Type": "application/x-www-form-urlencoded"
93111
}
94112
}, options);
@@ -102,21 +120,22 @@
102120
configurable: true
103121
},
104122
getRefreshToken: {
105-
value: function getRefreshToken() {
106-
var data = {
123+
value: function getRefreshToken(data, options) {
124+
data = angular.extend({
107125
client_id: config.clientId,
108126
grant_type: "refresh_token",
109127
refresh_token: OAuthToken.getRefreshToken()
110-
};
128+
}, data);
111129
if (null !== config.clientSecret) {
112130
data.client_secret = config.clientSecret;
113131
}
114132
data = queryString.stringify(data);
115-
var options = {
133+
options = angular.extend({
116134
headers: {
135+
Authorization: undefined,
117136
"Content-Type": "application/x-www-form-urlencoded"
118137
}
119-
};
138+
}, options);
120139
return $http.post("" + config.baseUrl + "" + config.grantPath, data, options).then(function(response) {
121140
OAuthToken.setToken(response.data);
122141
return response;
@@ -127,15 +146,22 @@
127146
configurable: true
128147
},
129148
revokeToken: {
130-
value: function revokeToken() {
131-
var data = queryString.stringify({
132-
token: OAuthToken.getRefreshToken() ? OAuthToken.getRefreshToken() : OAuthToken.getAccessToken()
133-
});
134-
var options = {
149+
value: function revokeToken(data, options) {
150+
var refreshToken = OAuthToken.getRefreshToken();
151+
data = angular.extend({
152+
client_id: config.clientId,
153+
token: refreshToken ? refreshToken : OAuthToken.getAccessToken(),
154+
token_type_hint: refreshToken ? "refresh_token" : "access_token"
155+
}, data);
156+
if (null !== config.clientSecret) {
157+
data.client_secret = config.clientSecret;
158+
}
159+
data = queryString.stringify(data);
160+
options = angular.extend({
135161
headers: {
136162
"Content-Type": "application/x-www-form-urlencoded"
137163
}
138-
};
164+
}, options);
139165
return $http.post("" + config.baseUrl + "" + config.revokePath, data, options).then(function(response) {
140166
OAuthToken.removeToken();
141167
return response;
@@ -240,27 +266,5 @@
240266
};
241267
this.$get.$inject = [ "$cookies" ];
242268
}
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" ];
265269
return ngModule;
266270
});

dist/angular-oauth2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-oauth2",
3-
"version": "3.0.1",
3+
"version": "3.1.0",
44
"description": "Angular OAuth2",
55
"main": "./dist/angular-oauth2.js",
66
"repository": {

0 commit comments

Comments
 (0)