Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.

Commit 666f08b

Browse files
refactor(portal): update fields and types (#161)
1 parent a316b28 commit 666f08b

7 files changed

Lines changed: 77 additions & 67 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ mod core;
66
mod known_or_unknown;
77
mod workos;
88

9-
pub mod admin_portal;
109
pub mod directory_sync;
1110
pub mod events;
1211
pub mod mfa;
1312
pub mod organizations;
1413
pub mod passwordless;
14+
pub mod portal;
1515
pub mod roles;
1616
pub mod sso;
1717
pub mod user_management;
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
//! [WorkOS Docs: Admin Portal Guide](https://workos.com/docs/admin-portal/guide)
44
55
mod operations;
6+
mod types;
67

78
pub use operations::*;
9+
pub use types::*;
810

911
use crate::WorkOs;
1012

1113
/// Admin Portal.
1214
///
1315
/// [WorkOS Docs: Admin Portal Guide](https://workos.com/docs/admin-portal/guide)
14-
pub struct AdminPortal<'a> {
16+
pub struct Portal<'a> {
1517
workos: &'a WorkOs,
1618
}
1719

18-
impl<'a> AdminPortal<'a> {
20+
impl<'a> Portal<'a> {
1921
/// Returns a new [`AdminPortal`] instance for the provided WorkOS client.
2022
pub fn new(workos: &'a WorkOs) -> Self {
2123
Self { workos }
Lines changed: 38 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,33 @@
11
use async_trait::async_trait;
22
use serde::{Deserialize, Serialize};
33

4-
use crate::admin_portal::AdminPortal;
54
use crate::organizations::OrganizationId;
5+
use crate::portal::{GeneratePortalLinkIntent, Portal};
66
use crate::{ResponseExt, WorkOsResult};
77

8-
/// The intent of an Admin Portal session.
9-
#[derive(Clone, Copy, Debug, Serialize)]
10-
#[serde(rename_all = "snake_case")]
11-
pub enum AdminPortalIntent {
12-
/// The Admin Portal will be used to setup Single Sign-On (SSO).
13-
Sso,
14-
15-
/// The Admin Portal wil be used to setup Directory Sync.
16-
#[serde(rename = "dsync")]
17-
DirectorySync,
18-
}
19-
20-
/// The target of the Admin Portal.
21-
#[derive(Debug, Serialize)]
22-
#[serde(untagged, rename_all = "snake_case")]
23-
pub enum AdminPortalTarget {
24-
/// The Admin Portal session should target an organization.
25-
Organization {
26-
/// The ID of the organization.
27-
#[serde(rename = "organization")]
28-
organization_id: OrganizationId,
29-
30-
/// The intent of the Admin Portal session.
31-
intent: AdminPortalIntent,
32-
},
33-
}
34-
358
/// The parameters for [`GeneratePortalLink`].
369
#[derive(Debug, Serialize)]
3710
pub struct GeneratePortalLinkParams<'a> {
38-
/// The target of the Admin Portal.
39-
#[serde(flatten)]
40-
pub target: &'a AdminPortalTarget,
11+
/// The ID of the organization.
12+
#[serde(rename = "organization")]
13+
pub organization_id: &'a OrganizationId,
14+
15+
/// The intent of the Admin Portal.
16+
pub intent: GeneratePortalLinkIntent,
17+
18+
/// The URL to go to when an admin clicks on your logo in the Admin Portal.
19+
#[serde(skip_serializing_if = "Option::is_none")]
20+
pub return_url: Option<&'a str>,
4121

42-
/// The URL to which the Admin Portal should send users when they click on the link
43-
/// to return to your application.
22+
/// The URL to redirect the admin to when they finish setup.
4423
#[serde(skip_serializing_if = "Option::is_none")]
45-
pub return_url: Option<String>,
24+
pub success_url: Option<&'a str>,
4625
}
4726

4827
/// The response for [`GeneratePortalLink`].
4928
#[derive(Debug, Deserialize)]
5029
pub struct GeneratePortalLinkResponse {
51-
/// The generate Admin Portal link.
30+
/// An ephemeral link to initiate the Admin Portal.
5231
pub link: String,
5332
}
5433

@@ -59,29 +38,28 @@ pub enum GeneratePortalLinkError {}
5938
/// [WorkOS Docs: Generate a Portal Link](https://workos.com/docs/reference/admin-portal/portal-link/generate)
6039
#[async_trait]
6140
pub trait GeneratePortalLink {
62-
/// Generates an Admin Portal link.
41+
/// Generate a Portal Link scoped to an Organization.
6342
///
6443
/// [WorkOS Docs: Generate a Portal Link](https://workos.com/docs/reference/admin-portal/portal-link/generate)
6544
///
6645
/// # Examples
6746
///
6847
/// ```
6948
/// # use workos::WorkOsResult;
70-
/// # use workos::admin_portal::*;
7149
/// # use workos::organizations::OrganizationId;
50+
/// # use workos::portal::*;
7251
/// use workos::{ApiKey, WorkOs};
7352
///
7453
/// # async fn run() -> WorkOsResult<(), GeneratePortalLinkError> {
7554
/// let workos = WorkOs::new(&ApiKey::from("sk_example_123456789"));
7655
///
7756
/// let GeneratePortalLinkResponse { link } = workos
78-
/// .admin_portal()
57+
/// .portal()
7958
/// .generate_portal_link(&GeneratePortalLinkParams {
80-
/// target: &AdminPortalTarget::Organization {
81-
/// organization_id: OrganizationId::from("org_01EHZNVPK3SFK441A1RGBFSHRT"),
82-
/// intent: AdminPortalIntent::Sso,
83-
/// },
59+
/// organization_id: &OrganizationId::from("org_01EHZNVPK3SFK441A1RGBFSHRT"),
60+
/// intent: GeneratePortalLinkIntent::Sso,
8461
/// return_url: None,
62+
/// success_url: None,
8563
/// })
8664
/// .await?;
8765
/// # Ok(())
@@ -94,13 +72,13 @@ pub trait GeneratePortalLink {
9472
}
9573

9674
#[async_trait]
97-
impl GeneratePortalLink for AdminPortal<'_> {
75+
impl GeneratePortalLink for Portal<'_> {
9876
async fn generate_portal_link(
9977
&self,
10078
params: &GeneratePortalLinkParams<'_>,
10179
) -> WorkOsResult<GeneratePortalLinkResponse, GeneratePortalLinkError> {
10280
let url = self.workos.base_url().join("/portal/generate_link")?;
103-
let generate_link_response = self
81+
let response = self
10482
.workos
10583
.client()
10684
.post(url)
@@ -113,12 +91,13 @@ impl GeneratePortalLink for AdminPortal<'_> {
11391
.json::<GeneratePortalLinkResponse>()
11492
.await?;
11593

116-
Ok(generate_link_response)
94+
Ok(response)
11795
}
11896
}
11997

12098
#[cfg(test)]
12199
mod test {
100+
use mockito::Matcher;
122101
use serde_json::json;
123102
use tokio;
124103

@@ -136,33 +115,34 @@ mod test {
136115
.unwrap()
137116
.build();
138117

139-
server.mock("POST", "/portal/generate_link")
118+
server
119+
.mock("POST", "/portal/generate_link")
140120
.match_header("Authorization", "Bearer sk_example_123456789")
141-
.match_body(r#"{"organization":"org_01EHZNVPK3SFK441A1RGBFSHRT","intent":"sso"}"#)
121+
.match_body(Matcher::Json(json!({
122+
"organization": "org_01EHZNVPK3SFK441A1RGBFSHRT",
123+
"intent": "sso",
124+
})))
142125
.with_status(201)
143126
.with_body(
144127
json!({
145-
"link": "https://setup.workos.com/portal/launch?secret=JteZqfJZqUcgWGaYCC6iI0gW0"
128+
"link": "https://setup.workos.com?token=token"
146129
})
147130
.to_string(),
148131
)
149-
.create_async().await;
132+
.create_async()
133+
.await;
150134

151135
let GeneratePortalLinkResponse { link } = workos
152-
.admin_portal()
136+
.portal()
153137
.generate_portal_link(&GeneratePortalLinkParams {
154-
target: &AdminPortalTarget::Organization {
155-
organization_id: OrganizationId::from("org_01EHZNVPK3SFK441A1RGBFSHRT"),
156-
intent: AdminPortalIntent::Sso,
157-
},
138+
organization_id: &OrganizationId::from("org_01EHZNVPK3SFK441A1RGBFSHRT"),
139+
intent: GeneratePortalLinkIntent::Sso,
158140
return_url: None,
141+
success_url: None,
159142
})
160143
.await
161144
.unwrap();
162145

163-
assert_eq!(
164-
link,
165-
"https://setup.workos.com/portal/launch?secret=JteZqfJZqUcgWGaYCC6iI0gW0".to_string()
166-
)
146+
assert_eq!(link, "https://setup.workos.com?token=token".to_string())
167147
}
168148
}

src/portal/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod generate_portal_link_intent;
2+
3+
pub use generate_portal_link_intent::*;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use serde::Serialize;
2+
3+
/// The intent of the Admin Portal.
4+
#[derive(Clone, Copy, Debug, Serialize)]
5+
#[serde(rename_all = "snake_case")]
6+
pub enum GeneratePortalLinkIntent {
7+
/// Launch Admin Portal for creating SSO connections
8+
Sso,
9+
10+
/// Launch Admin Portal for creating Directory Sync connections
11+
#[serde(rename = "dsync")]
12+
DirectorySync,
13+
14+
/// Launch Admin Portal for viewing Audit Logs
15+
AuditLogs,
16+
17+
/// Launch Admin Portal for creating Log Streams
18+
LogStreams,
19+
20+
/// Launch Admin Portal for Domain Verification.
21+
DomainVerification,
22+
23+
/// Launch Admin Portal for renewing SAML Certificates.
24+
CertificateRenewal,
25+
}

src/workos.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use url::{ParseError, Url};
22

33
use crate::ApiKey;
4-
use crate::admin_portal::AdminPortal;
54
use crate::directory_sync::DirectorySync;
65
use crate::events::Events;
76
use crate::mfa::Mfa;
87
use crate::organizations::Organizations;
98
use crate::passwordless::Passwordless;
9+
use crate::portal::Portal;
1010
use crate::roles::Roles;
1111
use crate::sso::Sso;
1212
use crate::user_management::UserManagement;
@@ -42,11 +42,6 @@ impl WorkOs {
4242
&self.client
4343
}
4444

45-
/// Returns an [`AdminPortal`] instance.
46-
pub fn admin_portal(&self) -> AdminPortal<'_> {
47-
AdminPortal::new(self)
48-
}
49-
5045
/// Returns a [`DirectorySync`] instance.
5146
pub fn directory_sync(&self) -> DirectorySync<'_> {
5247
DirectorySync::new(self)
@@ -72,6 +67,11 @@ impl WorkOs {
7267
Passwordless::new(self)
7368
}
7469

70+
/// Returns an [`AdminPortal`] instance.
71+
pub fn portal(&self) -> Portal<'_> {
72+
Portal::new(self)
73+
}
74+
7575
/// Returns an [`Roles`] instance.
7676
pub fn roles(&self) -> Roles<'_> {
7777
Roles::new(self)

0 commit comments

Comments
 (0)