Skip to content

Commit

Permalink
fix(backend): Expose user saml_accounts property (#3405)
Browse files Browse the repository at this point in the history
We fix an omission on our end where we didn't expose the 'saml_accounts' user
property and therefore customers were not able to use it via our SDK
  • Loading branch information
chanioxaris authored May 20, 2024
1 parent 456b068 commit 6888594
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-onions-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/backend': minor
---

Consume and expose the 'saml_accounts' property of the user resource
14 changes: 12 additions & 2 deletions packages/backend/src/api/resources/JSON.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { SamlAccountJSON } from '@clerk/types';

import type {
InvitationStatus,
OrganizationInvitationStatus,
Expand All @@ -23,6 +21,7 @@ export const ObjectType = {
OrganizationMembership: 'organization_membership',
PhoneNumber: 'phone_number',
RedirectUrl: 'redirect_url',
SamlAccount: 'saml_account',
Session: 'session',
SignInAttempt: 'sign_in_attempt',
SignInToken: 'sign_in_token',
Expand Down Expand Up @@ -104,6 +103,17 @@ export interface ExternalAccountJSON extends ClerkResourceJSON {
verification: VerificationJSON | null;
}

export interface SamlAccountJSON extends ClerkResourceJSON {
object: typeof ObjectType.SamlAccount;
provider: string;
provider_user_id: string | null;
active: boolean;
email_address: string;
first_name: string;
last_name: string;
verification: VerificationJSON | null;
}

export interface IdentificationLinkJSON extends ClerkResourceJSON {
type: string;
}
Expand Down
28 changes: 28 additions & 0 deletions packages/backend/src/api/resources/SamlAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { SamlAccountJSON } from './JSON';
import { Verification } from './Verification';

export class SamlAccount {
constructor(
readonly id: string,
readonly provider: string,
readonly providerUserId: string | null,
readonly active: boolean,
readonly emailAddress: string,
readonly firstName: string,
readonly lastName: string,
readonly verification: Verification | null,
) {}

static fromJSON(data: SamlAccountJSON): SamlAccount {
return new SamlAccount(
data.id,
data.provider,
data.provider_user_id,
data.active,
data.email_address,
data.first_name,
data.last_name,
data.verification && Verification.fromJSON(data.verification),
);
}
}
5 changes: 4 additions & 1 deletion packages/backend/src/api/resources/User.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { EmailAddress } from './EmailAddress';
import { ExternalAccount } from './ExternalAccount';
import type { ExternalAccountJSON, UserJSON } from './JSON';
import type { ExternalAccountJSON, SamlAccountJSON, UserJSON } from './JSON';
import { PhoneNumber } from './PhoneNumber';
import { SamlAccount } from './SamlAccount';
import { Web3Wallet } from './Web3Wallet';

export class User {
Expand Down Expand Up @@ -31,6 +32,7 @@ export class User {
readonly phoneNumbers: PhoneNumber[] = [],
readonly web3Wallets: Web3Wallet[] = [],
readonly externalAccounts: ExternalAccount[] = [],
readonly samlAccounts: SamlAccount[] = [],
readonly lastActiveAt: number | null,
readonly createOrganizationEnabled: boolean,
) {}
Expand Down Expand Up @@ -62,6 +64,7 @@ export class User {
(data.phone_numbers || []).map(x => PhoneNumber.fromJSON(x)),
(data.web3_wallets || []).map(x => Web3Wallet.fromJSON(x)),
(data.external_accounts || []).map((x: ExternalAccountJSON) => ExternalAccount.fromJSON(x)),
(data.saml_accounts || []).map((x: SamlAccountJSON) => SamlAccount.fromJSON(x)),
data.last_active_at,
data.create_organization_enabled,
);
Expand Down
18 changes: 18 additions & 0 deletions packages/backend/src/fixtures/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@
"verification": null
}
],
"saml_accounts": [
{
"object": "saml_account",
"id": "samlacc_microsoft",
"provider": "saml_microsoft",
"active": true,
"email_address": "john.doe@clerk.test",
"first_name": "John",
"last_name": "Doe",
"provider_user_id": null,
"verification": {
"status": "verified",
"strategy": "saml",
"attempts": null,
"expireAt": 1613831855
}
}
],
"public_metadata": {
"zodiac_sign": "leo"
},
Expand Down

0 comments on commit 6888594

Please sign in to comment.