Skip to content

Commit d25ea57

Browse files
fix(deps): update rust crate workos to v2 (#421)
* fix(deps): update rust crate workos to v2 * refactor: migrate to workos v2 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Daniëlle Huisman <danielle@huisman.me>
1 parent a2cb05c commit d25ea57

9 files changed

Lines changed: 84 additions & 351 deletions

File tree

Cargo.lock

Lines changed: 19 additions & 246 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/methods/shield-workos/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ bon.workspace = true
1414
serde.workspace = true
1515
serde_json.workspace = true
1616
shield.workspace = true
17-
workos = "0.8.0"
17+
workos = "2.0.0"

packages/methods/shield-workos/src/actions/index.rs

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::sync::Arc;
2-
31
use async_trait::async_trait;
42
use serde::Deserialize;
53
use shield::{
@@ -8,34 +6,37 @@ use shield::{
86
SignInAction, SignUpAction, erased_method_action,
97
};
108
use workos::{
11-
PaginationParams,
12-
sso::{ConnectionId, ListConnections, ListConnectionsParams},
13-
user_management::{
14-
ConnectionSelector, GetAuthorizationUrl, GetAuthorizationUrlParams, ListUsers,
15-
ListUsersParams, OauthProvider, Provider,
16-
},
9+
Client, UserManagementAuthenticationProvider,
10+
sso::ListConnectionsParams,
11+
user_management::{GetAuthorizationUrlParams, ListUsersParams},
1712
};
1813

19-
use crate::{client::WorkosClient, options::WorkosOptions, provider::WorkosProvider};
14+
use crate::{options::WorkosOptions, provider::WorkosProvider};
2015

2116
const ACTION_ID: &str = "index";
2217
const ACTION_NAME: &str = "Welcome";
2318

2419
#[derive(Debug, Deserialize)]
2520
#[serde(untagged, rename_all = "camelCase", rename_all_fields = "camelCase")]
2621
pub enum IndexData {
27-
Email { email: String },
28-
Oauth { oauth_provider: OauthProvider },
29-
Sso { connection_id: ConnectionId },
22+
Email {
23+
email: String,
24+
},
25+
Oauth {
26+
oauth_provider: UserManagementAuthenticationProvider,
27+
},
28+
Sso {
29+
connection_id: String,
30+
},
3031
}
3132

3233
pub struct WorkosIndexAction {
3334
options: WorkosOptions,
34-
client: Arc<WorkosClient>,
35+
client: Client,
3536
}
3637

3738
impl WorkosIndexAction {
38-
pub fn new(options: WorkosOptions, client: Arc<WorkosClient>) -> Self {
39+
pub fn new(options: WorkosOptions, client: Client) -> Self {
3940
Self { options, client }
4041
}
4142
}
@@ -66,11 +67,8 @@ impl MethodAction<WorkosProvider, ()> for WorkosIndexAction {
6667
let connections = self
6768
.client
6869
.sso()
69-
.list_connections(&ListConnectionsParams {
70-
pagination: PaginationParams {
71-
limit: Some(100),
72-
..Default::default()
73-
},
70+
.list_connections(ListConnectionsParams {
71+
limit: Some(100),
7472
..Default::default()
7573
})
7674
.await
@@ -131,10 +129,22 @@ impl MethodAction<WorkosProvider, ()> for WorkosIndexAction {
131129
value: format!(
132130
"Continue with {}",
133131
match oauth_provider {
134-
OauthProvider::AppleOAuth => "Apple",
135-
OauthProvider::GithubOAuth => "GitHub",
136-
OauthProvider::GoogleOAuth => "Google",
137-
OauthProvider::MicrosoftOAuth => "Microsoft",
132+
UserManagementAuthenticationProvider::Authkit => "Authkit".to_owned(),
133+
UserManagementAuthenticationProvider::AppleOAuth => "Apple".to_owned(),
134+
UserManagementAuthenticationProvider::BitbucketOAuth => "Bitbucket".to_owned(),
135+
UserManagementAuthenticationProvider::GitHubOAuth => "GitHub".to_owned(),
136+
UserManagementAuthenticationProvider::GitLabOAuth => "GitLab".to_owned(),
137+
UserManagementAuthenticationProvider::GoogleOAuth => "Google".to_owned(),
138+
UserManagementAuthenticationProvider::IntuitOAuth => "Intuit".to_owned(),
139+
UserManagementAuthenticationProvider::LinkedInOAuth => "LinkedIn".to_owned(),
140+
UserManagementAuthenticationProvider::MicrosoftOAuth => "Microsoft".to_owned(),
141+
UserManagementAuthenticationProvider::SalesforceOAuth => "Salesforce".to_owned(),
142+
UserManagementAuthenticationProvider::SlackOAuth => "Slack".to_owned(),
143+
UserManagementAuthenticationProvider::VercelMarketplaceOAuth => "Vercel Marketplace".to_owned(),
144+
UserManagementAuthenticationProvider::VercelOAuth => "Vercel".to_owned(),
145+
UserManagementAuthenticationProvider::XeroOAuth => "Xero".to_owned(),
146+
UserManagementAuthenticationProvider::Unknown(value) => value.replace("OAuth", ""),
147+
_ => "Unknown".to_owned()
138148
}
139149
)
140150
.to_owned(),
@@ -192,12 +202,9 @@ impl MethodAction<WorkosProvider, ()> for WorkosIndexAction {
192202
let users = self
193203
.client
194204
.user_management()
195-
.list_users(&ListUsersParams {
196-
pagination: PaginationParams {
197-
limit: Some(1),
198-
..Default::default()
199-
},
200-
email: Some(&email),
205+
.list_users(ListUsersParams {
206+
limit: Some(1),
207+
email: Some(email),
201208
..Default::default()
202209
})
203210
.await
@@ -218,17 +225,10 @@ impl MethodAction<WorkosProvider, ()> for WorkosIndexAction {
218225
let authorization_url = self
219226
.client
220227
.user_management()
221-
.get_authorization_url(&GetAuthorizationUrlParams {
222-
client_id: &self.client.client_id(),
223-
redirect_uri: &self.options.redirect_url,
224-
connection_selector: ConnectionSelector::Provider(&Provider::Oauth(
225-
oauth_provider,
226-
)),
228+
.get_authorization_url(GetAuthorizationUrlParams {
229+
provider: Some(oauth_provider),
227230
// TODO: State and code challenge.
228-
state: None,
229-
code_challenge: None,
230-
login_hint: None,
231-
domain_hint: None,
231+
..GetAuthorizationUrlParams::new(&self.options.redirect_url)
232232
})
233233
.expect("TODO: handle error");
234234

@@ -240,15 +240,10 @@ impl MethodAction<WorkosProvider, ()> for WorkosIndexAction {
240240
let authorization_url = self
241241
.client
242242
.user_management()
243-
.get_authorization_url(&GetAuthorizationUrlParams {
244-
client_id: &self.client.client_id(),
245-
redirect_uri: &self.options.redirect_url,
246-
connection_selector: ConnectionSelector::Connection(&connection_id),
243+
.get_authorization_url(GetAuthorizationUrlParams {
244+
connection_id: Some(connection_id),
247245
// TODO: State and code challenge.
248-
state: None,
249-
code_challenge: None,
250-
login_hint: None,
251-
domain_hint: None,
246+
..GetAuthorizationUrlParams::new(&self.options.redirect_url)
252247
})
253248
.expect("TODO: handle error");
254249

packages/methods/shield-workos/src/actions/sign_in.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
use std::sync::Arc;
2-
31
use async_trait::async_trait;
42
use shield::{
53
Form, Input, InputType, InputTypeEmail, InputTypeHidden, InputTypePassword, InputTypeSubmit,
64
InputValue, MethodAction, MethodSession, Request, RequestMethod, Response, ResponseType,
75
ShieldError, SignInAction, erased_method_action,
86
};
7+
use workos::Client;
98

10-
use crate::{client::WorkosClient, provider::WorkosProvider};
9+
use crate::provider::WorkosProvider;
1110

1211
pub struct WorkosSignInAction {
1312
// TODO: Remove expect.
1413
#[expect(unused)]
15-
client: Arc<WorkosClient>,
14+
client: Client,
1615
}
1716

1817
impl WorkosSignInAction {
19-
pub fn new(client: Arc<WorkosClient>) -> Self {
18+
pub fn new(client: Client) -> Self {
2019
Self { client }
2120
}
2221
}

packages/methods/shield-workos/src/actions/sign_up.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
use std::sync::Arc;
2-
31
use async_trait::async_trait;
42
use shield::{
53
Form, Input, InputType, InputTypeEmail, InputTypeHidden, InputTypePassword, InputTypeSubmit,
64
InputValue, MethodAction, MethodSession, Request, RequestMethod, Response, ResponseType,
75
ShieldError, SignUpAction, erased_method_action,
86
};
7+
use workos::Client;
98

10-
use crate::{client::WorkosClient, provider::WorkosProvider};
9+
use crate::provider::WorkosProvider;
1110

1211
pub struct WorkosSignUpAction {
1312
// TODO: Remove expect.
1413
#[expect(unused)]
15-
client: Arc<WorkosClient>,
14+
client: Client,
1615
}
1716

1817
impl WorkosSignUpAction {
19-
pub fn new(client: Arc<WorkosClient>) -> Self {
18+
pub fn new(client: Client) -> Self {
2019
Self { client }
2120
}
2221
}

packages/methods/shield-workos/src/client.rs

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mod actions;
2-
mod client;
32
mod method;
43
mod options;
54
mod provider;
@@ -8,9 +7,6 @@ pub use method::*;
87
pub use options::*;
98

109
#[doc(no_inline)]
11-
pub use workos::{
12-
ApiKey as WorkosApiKey, WorkOs as Workos, WorkOsBuilder as WorkosBuilder,
13-
user_management::OauthProvider as WorkosOauthProvider,
14-
};
10+
pub use workos::{Client as Workos, UserManagementAuthenticationProvider as WorkosOauthProvider};
1511

1612
// TODO: Support both AuthKit method and self hosted method.

packages/methods/shield-workos/src/method.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
use std::sync::Arc;
2-
31
use async_trait::async_trait;
42
use shield::{Method, MethodAction, ShieldError, erased_method};
5-
use workos::{ApiKey, WorkOs};
3+
use workos::Client;
64

75
use crate::{
86
actions::{WorkosIndexAction, WorkosSignInAction, WorkosSignUpAction},
9-
client::WorkosClient,
107
options::WorkosOptions,
118
provider::WorkosProvider,
129
};
@@ -17,19 +14,22 @@ pub const WORKOS_METHOD_ID: &str = "workos";
1714

1815
pub struct WorkosMethod {
1916
options: WorkosOptions,
20-
client: Arc<WorkosClient>,
17+
client: Client,
2118
}
2219

2320
impl WorkosMethod {
24-
pub fn new(client: WorkOs, client_id: &str, options: WorkosOptions) -> Self {
25-
Self {
26-
options,
27-
client: Arc::new(WorkosClient::new(client, client_id)),
28-
}
21+
pub fn new(client: Client, options: WorkosOptions) -> Self {
22+
Self { options, client }
2923
}
3024

3125
pub fn from_api_key(api_key: &str, client_id: &str, options: WorkosOptions) -> Self {
32-
Self::new(WorkOs::new(&ApiKey::from(api_key)), client_id, options)
26+
Self::new(
27+
Client::builder()
28+
.api_key(api_key)
29+
.client_id(client_id)
30+
.build(),
31+
options,
32+
)
3333
}
3434

3535
pub fn with_options(mut self, options: WorkosOptions) -> Self {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use bon::Builder;
2-
use workos::user_management::OauthProvider;
2+
use workos::UserManagementAuthenticationProvider;
33

44
#[derive(Builder, Clone, Debug)]
55
#[builder(on(String, into), state_mod(vis = "pub(crate)"))]
66
pub struct WorkosOptions {
77
#[builder(default)]
8-
pub(crate) oauth_providers: Vec<OauthProvider>,
8+
pub(crate) oauth_providers: Vec<UserManagementAuthenticationProvider>,
99
// TODO: Generate automatically?
1010
pub(crate) redirect_url: String,
1111
}

0 commit comments

Comments
 (0)