Skip to content

Commit 72fe845

Browse files
committed
fix: call token revocation endpoint on logout
1 parent f1fb3a4 commit 72fe845

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

packages/auth/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
"publishConfig": {
3232
"access": "public"
3333
},
34+
"engines": {
35+
"node": ">=10"
36+
},
3437
"scripts": {
3538
"build": "tsup src/index.ts --format esm,cjs --dts ",
3639
"dev": "tsup src/index.ts --format esm,cjs --watch --dts --sourcemap inline",

packages/auth/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const IDENTITY_ROOT = "https://identity.api.navigraph.com";
22
export const IDENTITY_DEVICE_AUTH = IDENTITY_ROOT + "/connect/deviceauthorization";
33
export const IDENTITY_ENDSESSION_ENDPOINT = IDENTITY_ROOT + "/connect/endsession";
4+
export const IDENTITY_REVOCATION_ENDPOINT = IDENTITY_ROOT + "/connect/revocation";

packages/auth/src/internal.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { IDENTITY_ENDSESSION_ENDPOINT } from "./constants";
1+
import { getApp, Logger } from "@navigraph/app";
2+
import { IDENTITY_REVOCATION_ENDPOINT } from "./constants";
23
import { authenticatedAxios } from "./network";
34
import { CustomStorage, Listener, StorageKeys, User } from "./public-types";
45

@@ -38,8 +39,24 @@ export const setUser = (user: User | null) => {
3839
export const setInitialized = (initialized: boolean) => (INITIALIZED = initialized);
3940

4041
export const signOut = () => {
42+
const app = getApp();
43+
const refreshToken = tokenStorage.getRefreshToken();
44+
45+
if (app && refreshToken) {
46+
authenticatedAxios
47+
.post(
48+
IDENTITY_REVOCATION_ENDPOINT,
49+
new URLSearchParams({
50+
client_id: app.clientId,
51+
client_secret: app.clientSecret,
52+
token__type_hint: "refresh_token",
53+
token: refreshToken,
54+
})
55+
)
56+
.catch(() => Logger.warning("Failed to revoke token on signout"));
57+
}
58+
4159
tokenStorage.setAccessToken();
4260
tokenStorage.setRefreshToken();
4361
setUser(null);
44-
authenticatedAxios.get(IDENTITY_ENDSESSION_ENDPOINT).catch(() => "");
4562
};

0 commit comments

Comments
 (0)