Skip to content

Commit d25f7c3

Browse files
fix: Allow using CST created with PAT to authenticate requests (#233)
Co-authored-by: Seam Bot <[email protected]>
1 parent 0a7fdf7 commit d25f7c3

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

src/lib/middleware/with-client-session.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,6 @@ export const withClientSession: Middleware<
9999
})
100100
}
101101

102-
if (publishable_key == null && api_key_id == null) {
103-
throw new UnauthorizedException({
104-
type: "unauthorized",
105-
message: "publishable key or api key must be set",
106-
})
107-
}
108-
109102
req.auth = {
110103
type: "client_session",
111104
client_session_id,

test/api/client_sessions/create.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,33 @@ test("POST /client_sessions/create api key", async (t: ExecutionContext) => {
5454
"Client session is correctly associated with the api key that was used to create it",
5555
)
5656
})
57+
58+
test("POST /client_sessions/create with PAT with workspace", async (t) => {
59+
const { axios, db } = await getTestServer(t, { seed: false })
60+
const seed_result = seedDatabase(db)
61+
62+
const {
63+
data: { client_session },
64+
} = await axios.post(
65+
"/client_sessions/create",
66+
{
67+
user_identifier_key: "[email protected]",
68+
},
69+
{
70+
headers: {
71+
Authorization: `Bearer ${seed_result.seam_at1_token}`,
72+
"Seam-Workspace": seed_result.seed_workspace_1,
73+
},
74+
},
75+
)
76+
77+
t.truthy(client_session.token)
78+
t.truthy(client_session.created_at)
79+
80+
// Verify that the CST can be used to authenticate requests
81+
axios.defaults.headers.common.Authorization = `Bearer ${client_session.token}`
82+
const {
83+
data: { devices },
84+
} = await axios.get("/devices/list")
85+
t.is(devices.length, 0)
86+
})

test/middleware/with-client-session.test.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,4 @@ test("withClientSession middleware - successful auth", async (t) => {
8585
)
8686
t.is(revokedErr?.status, 401)
8787
t.is(revokedErr?.response.error.type, "client_session_revoked")
88-
89-
// Test client session without api key or publishable key
90-
const invalid_session = db.addClientSession({
91-
workspace_id: seed_result.seed_workspace_1,
92-
})
93-
94-
const invalidSessionErr = await t.throwsAsync<SimpleAxiosError>(
95-
axios.get("/connected_accounts/get", {
96-
params: {
97-
connected_account_id: seed_result.john_connected_account_id,
98-
},
99-
headers: {
100-
Authorization: `Bearer ${invalid_session.token}`,
101-
},
102-
}),
103-
)
104-
t.is(invalidSessionErr?.status, 401)
105-
t.is(invalidSessionErr?.response.error.type, "unauthorized")
106-
t.is(
107-
invalidSessionErr?.response.error.message,
108-
"publishable key or api key must be set",
109-
)
11088
})

0 commit comments

Comments
 (0)