Skip to content

Commit 9c2bd2f

Browse files
committed
Update revokeToken to allow data and options override
1 parent ae7d562 commit 9c2bd2f

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/providers/oauth-provider.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,24 +178,31 @@ function OAuthProvider() {
178178
* Revokes the `token` and removes the stored `token` from cookies
179179
* using the `OAuthToken`.
180180
*
181+
* @param {object} data - Request content.
182+
* @param {object} options - Optional configuration.
181183
* @return {promise} A response promise.
182184
*/
183185

184-
revokeToken() {
185-
var data = {
186+
revokeToken(data, options) {
187+
var refreshToken = OAuthToken.getRefreshToken();
188+
189+
data = angular.extend({
186190
client_id: config.clientId,
187-
token: OAuthToken.getRefreshToken() ? OAuthToken.getRefreshToken() : OAuthToken.getAccessToken()
188-
};
191+
token: refreshToken ? refreshToken : OAuthToken.getAccessToken(),
192+
token_type_hint: refreshToken ? 'refresh_token' : 'access_token'
193+
}, data);
189194

190195
if (null !== config.clientSecret) {
191196
data.client_secret = config.clientSecret;
192197
}
193198

194199
data = queryString.stringify(data);
195200

196-
var options = {
197-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
198-
};
201+
options = angular.extend({
202+
headers: {
203+
'Content-Type': 'application/x-www-form-urlencoded'
204+
}
205+
}, options);
199206

200207
return $http.post(`${config.baseUrl}${config.revokePath}`, data, options).then((response) => {
201208
OAuthToken.removeToken();

test/unit/providers/oauth-provider.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,9 @@ describe('OAuthProvider', function() {
316316
queryString.stringify.firstCall.args.should.have.lengthOf(1);
317317
queryString.stringify.firstCall.args[0].should.eql({
318318
client_id: defaults.clientId,
319-
client_secret: defaults.clientSecret,
320-
token: 'bar'
319+
token: 'bar',
320+
token_type_hint: 'refresh_token',
321+
client_secret: defaults.clientSecret
321322
});
322323
queryString.stringify.restore();
323324
}));
@@ -334,6 +335,7 @@ describe('OAuthProvider', function() {
334335
queryString.stringify.firstCall.args[0].should.eql({
335336
client_id: defaults.clientId,
336337
token: 'foo',
338+
token_type_hint: 'access_token',
337339
client_secret: defaults.clientSecret
338340
});
339341
queryString.stringify.restore();
@@ -343,6 +345,7 @@ describe('OAuthProvider', function() {
343345
var data = queryString.stringify({
344346
client_id: defaults.clientId,
345347
token: undefined,
348+
token_type_hint: 'access_token',
346349
client_secret: defaults.clientSecret
347350
});
348351

@@ -367,6 +370,7 @@ describe('OAuthProvider', function() {
367370
var data = queryString.stringify({
368371
client_id: defaults.clientId,
369372
token: 'bar',
373+
token_type_hint: 'refresh_token',
370374
client_secret: defaults.clientSecret
371375
});
372376

0 commit comments

Comments
 (0)