Skip to content

Commit 914e990

Browse files
Bound JWT to its scope by embedding scope claim in payload (#39)
1 parent 2cd038c commit 914e990

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

js/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class NeetoJWT {
5252
const payload = {
5353
email: this.email,
5454
workspace: this.workspace,
55+
scope: this.scope,
5556
iat,
5657
exp,
5758
};

js/test/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,23 @@ describe("NeetoJWT", () => {
4242
const decoded = jwt.verify(token, publicKey, { algorithms: ["ES256"] });
4343
expect(decoded.email).toBe(email);
4444
expect(decoded.workspace).toBe(workspace);
45+
expect(decoded.scope).toBe("user");
4546
expect(decoded.iat).toBeDefined();
4647
expect(decoded.exp).toBeDefined();
4748
});
4849

50+
it("should embed scope in the JWT payload for consumer scope", () => {
51+
const neetoJWT = new NeetoJWT({
52+
email,
53+
privateKey,
54+
scope: "consumer",
55+
});
56+
const token = neetoJWT.generateJWT();
57+
const decoded = jwt.verify(token, publicKey, { algorithms: ["ES256"] });
58+
expect(decoded.scope).toBe("consumer");
59+
expect(decoded.workspace).toBe("app");
60+
});
61+
4962
it("should generate a login URL", () => {
5063
const neetoJWT = new NeetoJWT({ email, workspace, privateKey });
5164
const loginUrl = neetoJWT.generateLoginUrl(redirectUri);

0 commit comments

Comments
 (0)