1
- use crate :: models :: AppInfo ;
1
+ use crate :: auth :: Auth ;
2
2
use crate :: openapi:: apis:: configuration:: Configuration ;
3
- use crate :: openapi:: apis:: { apps_api, authenticate_api, transactions_api} ;
4
3
use crate :: user:: User ;
5
- use crate :: Error ;
6
4
7
5
pub struct PassageFlex {
8
6
app_id : String ,
9
- configuration : Configuration ,
7
+ pub auth : Auth ,
10
8
pub user : User ,
11
9
}
12
10
@@ -47,13 +45,10 @@ impl PassageFlex {
47
45
. build ( )
48
46
. expect ( "Failed to create reqwest client for Passage" ) ;
49
47
48
+ let auth = Auth :: new ( configuration. clone ( ) ) ;
50
49
let user = User :: new ( configuration. clone ( ) ) ;
51
50
52
- let mut client = Self {
53
- app_id,
54
- configuration,
55
- user,
56
- } ;
51
+ let mut client = Self { app_id, auth, user } ;
57
52
// Set the default server URL
58
53
client. set_server_url ( SERVER_URL . to_string ( ) ) ;
59
54
@@ -62,164 +57,7 @@ impl PassageFlex {
62
57
63
58
fn set_server_url ( & mut self , server_url : String ) {
64
59
self . user . configuration . base_path = format ! ( "{}/v1/apps/{}" , server_url, self . app_id) ;
65
- self . configuration . base_path = format ! ( "{}/v1/apps/{}" , server_url, self . app_id) ;
66
- }
67
-
68
- /// Retrieves information about the application.
69
- ///
70
- /// # Returns
71
- ///
72
- /// A `Result` containing the `AppInfo` struct or an `Error`.
73
- ///
74
- /// # Examples
75
- ///
76
- /// ```ignore
77
- /// use passage_flex::PassageFlex;
78
- ///
79
- /// let passage_flex = PassageFlex::new(
80
- /// std::env::var("PASSAGE_APP_ID").unwrap(),
81
- /// std::env::var("PASSAGE_API_KEY").unwrap(),
82
- /// );
83
- ///
84
- /// let app_info = passage_flex.get_app().await.unwrap();
85
- /// println!("{}", app_info.auth_origin);
86
- /// ```
87
- pub async fn get_app ( & self ) -> Result < Box < AppInfo > , Error > {
88
- apps_api:: get_app ( & self . configuration )
89
- . await
90
- . map ( |response| {
91
- Box :: new ( AppInfo {
92
- auth_origin : response. app . auth_origin ,
93
- id : response. app . id ,
94
- name : response. app . name ,
95
- } )
96
- } )
97
- . map_err ( Into :: into)
98
- }
99
-
100
- /// Creates a transaction to start a user's registration process.
101
- ///
102
- /// # Arguments
103
- ///
104
- /// * `external_id` - A unique, immutable string that represents the user.
105
- /// * `passkey_display_name` - The label for the user's passkey that they will see when logging in.
106
- ///
107
- /// # Returns
108
- ///
109
- /// A `Result` containing the transaction ID as a string or an `Error`.
110
- ///
111
- /// # Examples
112
- ///
113
- /// ```ignore
114
- /// use passage_flex::PassageFlex;
115
- ///
116
- /// let passage_flex = PassageFlex::new(
117
- /// std::env::var("PASSAGE_APP_ID").unwrap(),
118
- /// std::env::var("PASSAGE_API_KEY").unwrap(),
119
- /// );
120
- ///
121
- /// let transaction = passage_flex
122
- /// .create_register_transaction(
123
- /// "00000000-0000-0000-0000-000000000001".to_string(),
124
- /// "[email protected] ".to_string(),
125
- /// )
126
- /// .await
127
- /// .unwrap();
128
- /// ```
129
- pub async fn create_register_transaction (
130
- & self ,
131
- external_id : String ,
132
- passkey_display_name : String ,
133
- ) -> Result < String , Error > {
134
- transactions_api:: create_register_transaction (
135
- & self . configuration ,
136
- crate :: openapi:: models:: CreateTransactionRegisterRequest {
137
- external_id,
138
- passkey_display_name,
139
- } ,
140
- )
141
- . await
142
- . map ( |response| response. transaction_id )
143
- . map_err ( Into :: into)
144
- }
145
-
146
- /// Creates a transaction to start a user's authentication process.
147
- ///
148
- /// # Arguments
149
- ///
150
- /// * `external_id` - A unique, immutable string that represents the user.
151
- ///
152
- /// # Returns
153
- ///
154
- /// A `Result` containing the transaction ID as a string or an `Error`.
155
- ///
156
- /// # Examples
157
- ///
158
- /// ```ignore
159
- /// use passage_flex::PassageFlex;
160
- ///
161
- /// let passage_flex = PassageFlex::new(
162
- /// std::env::var("PASSAGE_APP_ID").unwrap(),
163
- /// std::env::var("PASSAGE_API_KEY").unwrap(),
164
- /// );
165
- ///
166
- /// let transaction = passage_flex
167
- /// .create_authenticate_transaction(
168
- /// "00000000-0000-0000-0000-000000000001".to_string(),
169
- /// )
170
- /// .await
171
- /// .unwrap();
172
- /// ```
173
- pub async fn create_authenticate_transaction (
174
- & self ,
175
- external_id : String ,
176
- ) -> Result < String , Error > {
177
- transactions_api:: create_authenticate_transaction (
178
- & self . configuration ,
179
- crate :: openapi:: models:: CreateTransactionAuthenticateRequest { external_id } ,
180
- )
181
- . await
182
- . map ( |response| response. transaction_id )
183
- . map_err ( Into :: into)
184
- }
185
-
186
- /// Verifies the nonce received from a WebAuthn registration or authentication ceremony.
187
- ///
188
- /// # Arguments
189
- ///
190
- /// * `nonce` - The nonce string to be verified.
191
- ///
192
- /// # Returns
193
- ///
194
- /// A `Result` containing the external ID as a string or an `Error`.
195
- ///
196
- /// # Examples
197
- ///
198
- /// ```ignore
199
- /// use passage_flex::PassageFlex;
200
- ///
201
- /// let passage_flex = PassageFlex::new(
202
- /// std::env::var("PASSAGE_APP_ID").unwrap(),
203
- /// std::env::var("PASSAGE_API_KEY").unwrap(),
204
- /// );
205
- ///
206
- /// match passage_flex.verify_nonce("01234567890123456789".to_string()).await {
207
- /// Ok(external_id) => {
208
- /// // use external_id to do things like generate and send your own auth token
209
- /// }
210
- /// Err(err) => {
211
- /// // nonce was invalid or unable to be verified
212
- /// }
213
- /// }
214
- /// ```
215
- pub async fn verify_nonce ( & self , nonce : String ) -> Result < String , Error > {
216
- authenticate_api:: authenticate_verify_nonce (
217
- & self . configuration ,
218
- crate :: openapi:: models:: Nonce { nonce } ,
219
- )
220
- . await
221
- . map ( |response| response. external_id )
222
- . map_err ( Into :: into)
60
+ self . auth . configuration . base_path = format ! ( "{}/v1/apps/{}" , server_url, self . app_id) ;
223
61
}
224
62
}
225
63
0 commit comments