-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): Create SamlConnectionApi and SamlConnection resource (#…
…2980) * feat(backend): Create SamlConnectionApi and SamlConnection resource * feat(backend): Use camelCase in class properties * Create afraid-stingrays-suffer.md * feat(backend): Create SamlConnectionApi and SamlConnection resource * feat(backend): Use camelCase in class properties * feat(backend): Add idpMetadata property * feat(backend): Move attribute mapping class in the saml connection resource file * Update packages/backend/src/api/resources/SamlConnection.ts Co-authored-by: Haris Chaniotakis <[email protected]> --------- Co-authored-by: Haris Chaniotakis <[email protected]>
- Loading branch information
1 parent
66b2836
commit 8c23651
Showing
7 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"@clerk/backend": patch | ||
--- | ||
|
||
Introduce `clerkClient.samlConnections` to expose `getSamlConnectionList`, `createSamlConnection`, `getSamlConnection`, `updateSamlConnection` and `deleteSamlConnection` endpoints. Introduce `SamlConnection` resource for BAPI. | ||
|
||
Example: | ||
``` | ||
import { clerkClient } from '@clerk/nextjs/server'; | ||
const samlConnection = await clerkClient.samlConnections.getSamlConnectionList(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import type { SamlIdpSlug } from '@clerk/types'; | ||
|
||
import { joinPaths } from '../../util/path'; | ||
import type { SamlConnection } from '../resources'; | ||
import { AbstractAPI } from './AbstractApi'; | ||
|
||
const basePath = '/saml_connections'; | ||
|
||
type SamlConnectionListParams = { | ||
limit?: number; | ||
offset?: number; | ||
}; | ||
type CreateSamlConnectionParams = { | ||
name: string; | ||
provider: SamlIdpSlug; | ||
domain: string; | ||
idpEntityId?: string; | ||
idpSsoUrl?: string; | ||
idpCertificate?: string; | ||
idpMetadataUrl?: string; | ||
idpMetadata?: string; | ||
attributeMapping?: { | ||
emailAddress?: string; | ||
firstName?: string; | ||
lastName?: string; | ||
userId?: string; | ||
}; | ||
}; | ||
|
||
type UpdateSamlConnectionParams = { | ||
name?: string; | ||
provider?: SamlIdpSlug; | ||
domain?: string; | ||
idpEntityId?: string; | ||
idpSsoUrl?: string; | ||
idpCertificate?: string; | ||
idpMetadataUrl?: string; | ||
idpMetadata?: string; | ||
attributeMapping?: { | ||
emailAddress?: string; | ||
firstName?: string; | ||
lastName?: string; | ||
userId?: string; | ||
}; | ||
active?: boolean; | ||
syncUserAttributes?: boolean; | ||
allowSubdomains?: boolean; | ||
allowIdpInitiated?: boolean; | ||
}; | ||
|
||
export class SamlConnectionAPI extends AbstractAPI { | ||
public async getSamlConnectionList(params: SamlConnectionListParams = {}) { | ||
return this.request<SamlConnection[]>({ | ||
method: 'GET', | ||
path: basePath, | ||
queryParams: params, | ||
}); | ||
} | ||
|
||
public async createSamlConnection(params: CreateSamlConnectionParams) { | ||
return this.request<SamlConnection>({ | ||
method: 'POST', | ||
path: basePath, | ||
bodyParams: params, | ||
}); | ||
} | ||
|
||
public async getSamlConnection(samlConnectionId: string) { | ||
this.requireId(samlConnectionId); | ||
return this.request<SamlConnection>({ | ||
method: 'GET', | ||
path: joinPaths(basePath, samlConnectionId), | ||
}); | ||
} | ||
|
||
public async updateSamlConnection(samlConnectionId: string, params: UpdateSamlConnectionParams = {}) { | ||
this.requireId(samlConnectionId); | ||
|
||
return this.request<SamlConnection>({ | ||
method: 'PATCH', | ||
path: joinPaths(basePath, samlConnectionId), | ||
bodyParams: params, | ||
}); | ||
} | ||
public async deleteSamlConnection(samlConnectionId: string) { | ||
this.requireId(samlConnectionId); | ||
return this.request<SamlConnection>({ | ||
method: 'DELETE', | ||
path: joinPaths(basePath, samlConnectionId), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type { AttributeMappingJSON, SamlConnectionJSON } from './JSON'; | ||
|
||
export class SamlConnection { | ||
constructor( | ||
readonly id: string, | ||
readonly name: string, | ||
readonly domain: string, | ||
readonly idpEntityId: string | null, | ||
readonly idpSsoUrl: string | null, | ||
readonly idpCertificate: string | null, | ||
readonly idpMetadataUrl: string | null, | ||
readonly idpMetadata: string | null, | ||
readonly acsUrl: string, | ||
readonly spEntityId: string, | ||
readonly spMetadataUrl: string, | ||
readonly active: boolean, | ||
readonly provider: string, | ||
readonly userCount: number, | ||
readonly syncUserAttributes: boolean, | ||
readonly allowSubdomains: boolean, | ||
readonly allowIdpInitiated: boolean, | ||
readonly createdAt: number, | ||
readonly updatedAt: number, | ||
readonly attributeMapping: AttributeMapping, | ||
) {} | ||
static fromJSON(data: SamlConnectionJSON): SamlConnection { | ||
return new SamlConnection( | ||
data.id, | ||
data.name, | ||
data.domain, | ||
data.idp_entity_id, | ||
data.idp_sso_url, | ||
data.idp_certificate, | ||
data.idp_metadata_url, | ||
data.idp_metadata, | ||
data.acs_url, | ||
data.sp_entity_id, | ||
data.sp_metadata_url, | ||
data.active, | ||
data.provider, | ||
data.user_count, | ||
data.sync_user_attributes, | ||
data.allow_subdomains, | ||
data.allow_idp_initiated, | ||
data.created_at, | ||
data.updated_at, | ||
data.attribute_mapping && AttributeMapping.fromJSON(data.attribute_mapping), | ||
); | ||
} | ||
} | ||
|
||
class AttributeMapping { | ||
constructor( | ||
readonly userId: string, | ||
readonly emailAddress: string, | ||
readonly firstName: string, | ||
readonly lastName: string, | ||
) {} | ||
|
||
static fromJSON(data: AttributeMappingJSON): AttributeMapping { | ||
return new AttributeMapping(data.user_id, data.email_address, data.first_name, data.last_name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters