Skip to content

Commit ce89293

Browse files
author
Kadi Kraman
authored
Merge pull request #407 from ehapmgs/fix/revoke-authorization
Fix/revoke authorization
2 parents 0be3441 + d001763 commit ce89293

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export interface RefreshResult {
9797
export interface RevokeConfiguration {
9898
tokenToRevoke: string;
9999
sendClientId?: boolean;
100+
includeBasicAuthorization?: boolean;
100101
}
101102

102103
export interface RefreshConfiguration {

index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import invariant from 'invariant';
22
import { NativeModules, Platform } from 'react-native';
3+
import base64 from 'react-native-base64';
34

45
const { RNAppAuth } = NativeModules;
56

@@ -229,8 +230,8 @@ export const refresh = (
229230
};
230231

231232
export const revoke = async (
232-
{ clientId, issuer, serviceConfiguration },
233-
{ tokenToRevoke, sendClientId = false }
233+
{ clientId, issuer, serviceConfiguration, clientSecret },
234+
{ tokenToRevoke, sendClientId = false, includeBasicAuthorization = false }
234235
) => {
235236
invariant(tokenToRevoke, 'Please include the token to revoke');
236237
validateClientId(clientId);
@@ -251,6 +252,12 @@ export const revoke = async (
251252
revocationEndpoint = openidConfig.revocation_endpoint;
252253
}
253254

255+
const headers = {
256+
'Content-Type': 'application/x-www-form-urlencoded',
257+
};
258+
if (includeBasicAuthorization) {
259+
headers.Authorization = `basic ${base64.encode(`${clientId}:${clientSecret}`)}`;
260+
}
254261
/**
255262
Identity Server insists on client_id being passed in the body,
256263
but Google does not. According to the spec, Google is right
@@ -259,9 +266,7 @@ export const revoke = async (
259266
**/
260267
return await fetch(revocationEndpoint, {
261268
method: 'POST',
262-
headers: {
263-
'Content-Type': 'application/x-www-form-urlencoded',
264-
},
269+
headers,
265270
body: `token=${tokenToRevoke}${sendClientId ? `&client_id=${clientId}` : ''}`,
266271
}).catch(error => {
267272
throw new Error('Failed to revoke token', error);

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
"react-native": "^0.50.3"
7373
},
7474
"dependencies": {
75-
"invariant": "^2.2.2"
75+
"invariant": "^2.2.2",
76+
"react-native-base64": "^0.0.2"
77+
},
78+
"jest": {
79+
"transformIgnorePatterns": [
80+
"node_modules/?!(react-native-base64)"
81+
]
7682
}
7783
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,6 +4113,11 @@ react-devtools-core@^2.5.0:
41134113
shell-quote "^1.6.1"
41144114
ws "^2.0.3"
41154115

4116+
react-native-base64@^0.0.2:
4117+
version "0.0.2"
4118+
resolved "https://registry.yarnpkg.com/react-native-base64/-/react-native-base64-0.0.2.tgz#c28463c2c6779ac3ec5fdd12979ebc8c5f9b410a"
4119+
integrity sha512-Fu/J1a2y0X22EJDWqJR2oEa1fpP4gTFjYxk8ElJdt1Yak3HOXmFJ7EohLVHU2DaQkgmKfw8qb7u/48gpzveRbg==
4120+
41164121
react-native@^0.50.3:
41174122
version "0.50.3"
41184123
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.50.3.tgz#91282bd5356cc7d794969cdc443cc764389b9af4"

0 commit comments

Comments
 (0)