Skip to content

Commit 7e11d0e

Browse files
committed
Routed consumer-scope JWT auth to the global app host while keeping the JWT workspace claim configurable
1 parent 914e990 commit 7e11d0e

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

js/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const TLD: Record<string, string> = {
66

77
export const USER_LOGIN_PATH = "/users/auth/jwt";
88
export const CONSUMER_LOGIN_PATH = "/consumers/auth/jwt";
9+
export const CONSUMER_WORKSPACE = "app";
910

1011
export const NEETO_URL_COMPONENT_REGEX = /neeto(\w+)/;
1112
export const NEETO_URL_PREFIX_REGEX = /^(https?:\/\/)?(www\.)?[\w-]+\./;

js/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import jwt from "jsonwebtoken";
2+
import { CONSUMER_WORKSPACE } from "./constants.js";
23
import type { Scope } from "./types.js";
34
import {
45
getClientAppName,
@@ -14,8 +15,6 @@ interface Options {
1415
scope?: Scope;
1516
}
1617

17-
const CONSUMER_WORKSPACE = "app";
18-
1918
class NeetoJWT {
2019
private email: string;
2120
private workspace: string;

js/src/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
CLIENT_APPS,
33
CONSUMER_LOGIN_PATH,
4+
CONSUMER_WORKSPACE,
45
NEETO_URL_COMPONENT_REGEX,
56
NEETO_URL_PREFIX_REGEX,
67
TLD,
@@ -22,9 +23,11 @@ export const getLoginUri = (
2223
const protocol =
2324
process.env.NEETO_JWT_ENV === "development" ? "http" : "https";
2425
const params = new URLSearchParams(searchParams).toString();
25-
const path = scope === "consumer" ? CONSUMER_LOGIN_PATH : USER_LOGIN_PATH;
26+
const isConsumer = scope === "consumer";
27+
const host = isConsumer ? CONSUMER_WORKSPACE : workspace;
28+
const path = isConsumer ? CONSUMER_LOGIN_PATH : USER_LOGIN_PATH;
2629

27-
return `${protocol}://${workspace}${getTopLevelDomain()}${path}?${params}`;
30+
return `${protocol}://${host}${getTopLevelDomain()}${path}?${params}`;
2831
};
2932

3033
export const getTopLevelDomain = () => {

js/test/index.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,23 @@ describe("NeetoJWT", () => {
152152
}
153153
});
154154

155-
it("should honour an explicit consumer-scope workspace override", () => {
155+
it("should send consumer scope to the global app host regardless of workspace override, while preserving the workspace claim", () => {
156156
const neetoJWT = new NeetoJWT({
157157
email,
158158
privateKey,
159-
workspace: "staging-app",
159+
workspace: "spinkart",
160160
scope: "consumer",
161161
});
162162
const loginUrl = neetoJWT.generateLoginUrl("http://partner.example.com/cb");
163163
expect(loginUrl).toContain(
164-
"https://staging-app.neetoauth.com/consumers/auth/jwt"
164+
"https://app.neetoauth.com/consumers/auth/jwt"
165165
);
166+
167+
const token = new URL(loginUrl).searchParams.get("jwt") as string;
168+
const payload = JSON.parse(
169+
Buffer.from(token.split(".")[1], "base64").toString()
170+
);
171+
expect(payload.workspace).toBe("spinkart");
166172
});
167173

168174
it("should not double-encode the consumer redirect URI", () => {

0 commit comments

Comments
 (0)