Skip to content

Commit 3a00f9d

Browse files
authored
Add externalId to payload of auth token (#1640)
Part of OPS-2945
1 parent 53d10b9 commit 3a00f9d

5 files changed

Lines changed: 20 additions & 0 deletions

File tree

packages/server/api/src/app/authentication/context/create-project-auth-context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export async function getProjectAndToken(
4040

4141
const token = await accessTokenManager.generateToken({
4242
id: user.id,
43+
externalId: user.externalId,
4344
type: PrincipalType.USER,
4445
projectId: project.id,
4546
organization: {

packages/server/api/src/app/authentication/new-user/create-user.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type NewUserParams = {
2323
verified: boolean;
2424
organizationId: string | null;
2525
provider: Provider;
26+
externalId?: string;
2627
};
2728

2829
type NewUserResponse = {
@@ -70,6 +71,7 @@ const createEditorUser = async (
7071
newsLetter: params.newsLetter,
7172
password: params.password,
7273
organizationId: params.organizationId,
74+
externalId: params.externalId,
7375
};
7476

7577
return await userService.create(newUser);

packages/server/api/src/app/user/user-service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ export const userService = {
211211
});
212212
},
213213

214+
async updateExternalId({
215+
id,
216+
newExternalId,
217+
}: UpdateExternalIdParams): Promise<void> {
218+
await userRepo().update(id, {
219+
updated: dayjs().toISOString(),
220+
externalId: newExternalId,
221+
});
222+
},
223+
214224
async updateTracking({
215225
id,
216226
trackEvents,
@@ -322,6 +332,11 @@ type UpdateEmailParams = {
322332
newEmail: string;
323333
};
324334

335+
type UpdateExternalIdParams = {
336+
id: UserId;
337+
newExternalId?: string;
338+
};
339+
325340
type UpdateTrackingParams = {
326341
id: UserId;
327342
trackEvents: boolean;

packages/server/api/test/integration/ce/authentication/signup.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ beforeAll(async () => {
8484

8585
adminToken = await accessTokenManager.generateToken({
8686
id: mockAdminUser.id,
87+
externalId: mockAdminUser.externalId,
8788
type: PrincipalType.USER,
8889
projectId: mockProject.id,
8990
organization: {

packages/shared/src/lib/authentication/model/principal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { PrincipalType } from './principal-type';
55

66
export type Principal = {
77
id: OpenOpsId;
8+
externalId?: string;
89
type: PrincipalType;
910
projectId: ProjectId;
1011
organization: {

0 commit comments

Comments
 (0)