1- use std:: sync:: Arc ;
2-
31use async_trait:: async_trait;
42use serde:: Deserialize ;
53use shield:: {
@@ -8,34 +6,37 @@ use shield::{
86 SignInAction , SignUpAction , erased_method_action,
97} ;
108use 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
2116const ACTION_ID : & str = "index" ;
2217const ACTION_NAME : & str = "Welcome" ;
2318
2419#[ derive( Debug , Deserialize ) ]
2520#[ serde( untagged, rename_all = "camelCase" , rename_all_fields = "camelCase" ) ]
2621pub 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
3233pub struct WorkosIndexAction {
3334 options : WorkosOptions ,
34- client : Arc < WorkosClient > ,
35+ client : Client ,
3536}
3637
3738impl 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
0 commit comments