Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/famous-coats-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navigraph/auth": patch
---

Call token revocation endpoint on signout instead of calling endsession.
3 changes: 3 additions & 0 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=10"
},
"scripts": {
"build": "tsup src/index.ts --format esm,cjs --dts ",
"dev": "tsup src/index.ts --format esm,cjs --watch --dts --sourcemap inline",
Expand Down
1 change: 1 addition & 0 deletions packages/auth/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const IDENTITY_ROOT = "https://identity.api.navigraph.com";
export const IDENTITY_DEVICE_AUTH = IDENTITY_ROOT + "/connect/deviceauthorization";
export const IDENTITY_ENDSESSION_ENDPOINT = IDENTITY_ROOT + "/connect/endsession";
export const IDENTITY_REVOCATION_ENDPOINT = IDENTITY_ROOT + "/connect/revocation";
21 changes: 19 additions & 2 deletions packages/auth/src/internal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IDENTITY_ENDSESSION_ENDPOINT } from "./constants";
import { getApp, Logger } from "@navigraph/app";
import { IDENTITY_REVOCATION_ENDPOINT } from "./constants";
import { authenticatedAxios } from "./network";
import { CustomStorage, Listener, StorageKeys, User } from "./public-types";

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

export const signOut = () => {
const app = getApp();
const refreshToken = tokenStorage.getRefreshToken();

if (app && refreshToken) {
authenticatedAxios
.post(
IDENTITY_REVOCATION_ENDPOINT,
new URLSearchParams({
client_id: app.clientId,
client_secret: app.clientSecret,
token__type_hint: "refresh_token",
token: refreshToken,
})
)
.catch(() => Logger.warning("Failed to revoke token on signout"));
}

tokenStorage.setAccessToken();
tokenStorage.setRefreshToken();
setUser(null);
authenticatedAxios.get(IDENTITY_ENDSESSION_ENDPOINT).catch(() => "");
};
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"moduleResolution": "node",
"skipLibCheck": true,
"strict": true,
"noImplicitAny": true,
"isolatedModules": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
Expand Down