Skip to content

Commit 72a8baf

Browse files
authored
Merge pull request #227 from authts/fix-225
fix 225
2 parents 8766545 + f15ba9e commit 72a8baf

File tree

11 files changed

+345
-151
lines changed

11 files changed

+345
-151
lines changed

docs/oidc-client-ts.api.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class MetadataService {
186186
// (undocumented)
187187
protected _getMetadataProperty(name: keyof OidcMetadata, optional?: boolean): Promise<string | boolean | string[] | undefined>;
188188
// (undocumented)
189-
getRevocationEndpoint(): Promise<string | undefined>;
189+
getRevocationEndpoint(optional?: boolean): Promise<string | undefined>;
190190
// (undocumented)
191191
getSigningKeys(): Promise<SigningKey[] | null>;
192192
// (undocumented)
@@ -699,15 +699,6 @@ export interface StateStore {
699699
set(key: string, value: string): Promise<void>;
700700
}
701701

702-
// @public (undocumented)
703-
export class TokenRevocationClient {
704-
constructor(settings: OidcClientSettingsStore, metadataService: MetadataService);
705-
// (undocumented)
706-
revoke(token: string, required: boolean, type?: string): Promise<void>;
707-
// (undocumented)
708-
protected _revoke(url: string, client_id: string, client_secret: string | undefined, token: string, type: string): Promise<void>;
709-
}
710-
711702
// @public (undocumented)
712703
export class User {
713704
constructor(args: {
@@ -775,11 +766,7 @@ export class UserManager {
775766
// (undocumented)
776767
revokeAccessToken(): Promise<void>;
777768
// (undocumented)
778-
protected _revokeAccessTokenInternal(access_token: string, required: boolean): Promise<boolean>;
779-
// (undocumented)
780-
protected _revokeInternal(user: User | null, required?: boolean): Promise<boolean>;
781-
// (undocumented)
782-
protected _revokeRefreshTokenInternal(refresh_token: string | undefined, required: boolean): Promise<boolean>;
769+
protected _revokeInternal(user: User | null, optional: boolean): Promise<boolean>;
783770
// (undocumented)
784771
protected readonly _sessionMonitor: SessionMonitor | null;
785772
readonly settings: UserManagerSettingsStore;
@@ -826,8 +813,6 @@ export class UserManager {
826813
// (undocumented)
827814
protected readonly _tokenClient: TokenClient;
828815
// (undocumented)
829-
protected readonly _tokenRevocationClient: TokenRevocationClient;
830-
// (undocumented)
831816
protected _useRefreshToken(user: User): Promise<User>;
832817
// (undocumented)
833818
protected get _userStoreKey(): string;

samples/Parcel/src/code-flow-identityserver/sample.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<button id="getUser">get user</button>
1515
<button id="removeUser">remove user</button>
1616
<button id="querySessionStatus">query user status at token server</button>
17+
<button id="revokeAccessToken">revoke access token</button>
1718
</div>
1819
<div>
1920
<button id="startSigninMainWindow">start signin main window</button>

samples/Parcel/src/code-flow-identityserver/sample.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ document.getElementById("clearState").addEventListener("click", clearState, fals
1010
document.getElementById("getUser").addEventListener("click", getUser, false);
1111
document.getElementById("removeUser").addEventListener("click", removeUser, false);
1212
document.getElementById("querySessionStatus").addEventListener("click", querySessionStatus, false);
13+
document.getElementById("revokeAccessToken").addEventListener("click", revokeAccessToken, false);
1314

1415
document.getElementById("startSigninMainWindow").addEventListener("click", startSigninMainWindow, false);
1516
document.getElementById("endSigninMainWindow").addEventListener("click", endSigninMainWindow, false);
@@ -114,6 +115,22 @@ function removeUser() {
114115
});
115116
}
116117

118+
function querySessionStatus() {
119+
mgr.querySessionStatus().then(function(status) {
120+
log("user's session status", status);
121+
}).catch(function(err) {
122+
log(err);
123+
});
124+
}
125+
126+
function revokeAccessToken() {
127+
mgr.revokeAccessToken().then(function() {
128+
log("access token revoked");
129+
}).catch(function(err) {
130+
log(err);
131+
});
132+
}
133+
117134
function startSigninMainWindow() {
118135
mgr.signinRedirect(/*{useReplaceToNavigate:true}*/).then(function() {
119136
log("signinRedirect done");
@@ -158,14 +175,6 @@ function iframeSignin() {
158175
});
159176
}
160177

161-
function querySessionStatus() {
162-
mgr.querySessionStatus().then(function(status) {
163-
log("user's session status", status);
164-
}).catch(function(err) {
165-
log(err);
166-
});
167-
}
168-
169178
function startSignoutMainWindow() {
170179
mgr.signoutRedirect().then(function(resp) {
171180
log("signed out", resp);

src/JsonService.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ describe("JsonService", () => {
233233
Accept: "application/json",
234234
"Content-Type": "application/json"
235235
}),
236-
json: () => Promise.resolve(json)
236+
text: () => Promise.resolve(JSON.stringify(json))
237237
} as Response);
238238

239239
// act
@@ -263,7 +263,7 @@ describe("JsonService", () => {
263263
Accept: "application/json",
264264
"Content-Type": "application/json"
265265
}),
266-
json: () => Promise.reject(error)
266+
text: () => Promise.reject(error)
267267
} as Response);
268268

269269
// act
@@ -282,7 +282,7 @@ describe("JsonService", () => {
282282
Accept: "application/json",
283283
"Content-Type": "text/html"
284284
}),
285-
json: () => Promise.resolve(json)
285+
text: () => Promise.resolve(JSON.stringify(json))
286286
} as Response);
287287

288288
// act
@@ -301,7 +301,7 @@ describe("JsonService", () => {
301301
Accept: "application/json",
302302
"Content-Type": "application/json"
303303
}),
304-
json: () => Promise.resolve(json)
304+
text: () => Promise.resolve(JSON.stringify(json))
305305
} as Response);
306306

307307
// act
@@ -320,7 +320,7 @@ describe("JsonService", () => {
320320
Accept: "application/json",
321321
"Content-Type": "application/json"
322322
}),
323-
json: () => Promise.resolve(json)
323+
text: () => Promise.resolve(JSON.stringify(json))
324324
} as Response);
325325

326326
// act
@@ -339,7 +339,7 @@ describe("JsonService", () => {
339339
Accept: "application/json",
340340
"Content-Type": "application/json"
341341
}),
342-
json: () => Promise.reject(new SyntaxError("Unexpected token a in JSON"))
342+
text: () => Promise.resolve("not_json_data")
343343
} as Response);
344344

345345
// act
@@ -358,7 +358,7 @@ describe("JsonService", () => {
358358
Accept: "application/json",
359359
"Content-Type": "text/html"
360360
}),
361-
json: () => Promise.resolve(json)
361+
text: () => Promise.resolve(JSON.stringify(json))
362362
} as Response);
363363

364364
// act
@@ -369,11 +369,13 @@ describe("JsonService", () => {
369369

370370
it("should reject promise when http response is not 200", async () => {
371371
// arrange
372+
const json = {};
372373
mocked(fetch).mockResolvedValue({
373374
status: 500,
374375
statusText: "server error",
375376
ok: false,
376377
headers: new Headers(),
378+
text: () => Promise.resolve(JSON.stringify(json))
377379
} as Response);
378380

379381
// act
@@ -393,7 +395,7 @@ describe("JsonService", () => {
393395
Accept: "application/json",
394396
"Content-Type": "foo/bar"
395397
}),
396-
json: () => Promise.resolve(json)
398+
text: () => Promise.resolve(JSON.stringify(json))
397399
} as Response);
398400

399401
// act

src/JsonService.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,27 @@ export class JsonService {
9999
if (contentType && !this._contentTypes.find(item => contentType.startsWith(item))) {
100100
throw new Error(`Invalid response Content-Type: ${(contentType ?? "undefined")}, from URL: ${url}`);
101101
}
102-
let json: Record<string, unknown>;
102+
103+
const responseText = await response.text();
104+
105+
let json: Record<string, unknown> = {};
103106
try {
104-
json = await response.json();
107+
json = JSON.parse(responseText);
105108
}
106109
catch (err) {
107110
this._logger.error("postForm: Error parsing JSON response", err);
108111
if (response.ok) throw err;
109112
throw new Error(`${response.statusText} (${response.status})`);
110113
}
114+
111115
if (!response.ok) {
112116
this._logger.error("postForm: Error from server:", json);
113117
if (json.error) {
114118
throw new ErrorResponse(json);
115119
}
116120
throw new Error(`${response.statusText} (${response.status}): ${JSON.stringify(json)}`);
117121
}
122+
118123
return json;
119124
}
120125
}

src/MetadataService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ export class MetadataService {
100100
return this._getMetadataProperty("end_session_endpoint", true) as Promise<string | undefined>;
101101
}
102102

103-
public getRevocationEndpoint(): Promise<string | undefined> {
104-
return this._getMetadataProperty("revocation_endpoint", true) as Promise<string | undefined>;
103+
public getRevocationEndpoint(optional = true): Promise<string | undefined> {
104+
return this._getMetadataProperty("revocation_endpoint", optional) as Promise<string | undefined>;
105105
}
106106

107107
public getKeysEndpoint(optional?: true): Promise<string | undefined>

0 commit comments

Comments
 (0)