@@ -25,27 +25,44 @@ use crate::{
2525 dbus:: ui_control:: UiController ,
2626 model:: { CredentialRequest , CredentialResponse } ,
2727} ;
28+ pub struct UiRequestContext {
29+ request : CredentialRequest ,
30+ app : RequestingApplication ,
31+ /// Client window handle
32+ window_handle : Option < WindowHandle > ,
33+ activation_token : Option < String > ,
34+ response_channel : oneshot:: Sender < Result < CredentialResponse , CredentialServiceError > > ,
35+ }
2836
2937pub async fn start_flow_control_service < M : ManageDevice + Debug + Send + Sync + ' static > (
3038 conn : Connection ,
31- mut listener : Receiver < (
32- CredentialRequest ,
33- RequestingApplication ,
34- Option < WindowHandle > , // Client window handle
35- oneshot:: Sender < Result < CredentialResponse , CredentialServiceError > > ,
36- ) > ,
39+ mut listener : Receiver < UiRequestContext > ,
3740 device_manager : M ,
3841) -> zbus:: Result < AbortHandle > {
3942 let svc = Arc :: new ( AsyncMutex :: new ( device_manager) ) ;
4043 let svc2 = svc. clone ( ) ;
4144
4245 let task = tokio:: spawn ( async move {
43- while let Some ( ( msg , requesting_app , window_handle , tx ) ) = listener. recv ( ) . await {
46+ while let Some ( ui_request_ctx ) = listener. recv ( ) . await {
4447 let svc = svc2. clone ( ) ;
4548 let ui_control_client = UiControlServiceClient :: new ( conn. clone ( ) ) ;
46- if let Err ( _) =
47- tx. send ( handle ( svc, ui_control_client, msg, requesting_app, window_handle) . await )
48- {
49+ let UiRequestContext {
50+ request,
51+ app,
52+ window_handle,
53+ activation_token,
54+ response_channel,
55+ } = ui_request_ctx;
56+ let response = handle (
57+ svc,
58+ ui_control_client,
59+ request,
60+ app,
61+ window_handle,
62+ activation_token,
63+ )
64+ . await ;
65+ if let Err ( _) = response_channel. send ( response) {
4966 tracing:: error!(
5067 "Received response to credential request, but failed to forward it to gateway"
5168 ) ;
@@ -61,6 +78,7 @@ async fn handle<M: ManageDevice + Debug + Send + Sync + 'static, UC: UiControlle
6178 msg : CredentialRequest ,
6279 requesting_app : RequestingApplication ,
6380 window_handle : Option < WindowHandle > ,
81+ activation_token : Option < String > ,
6482) -> Result < CredentialResponse , CredentialServiceError > {
6583 let ( request_tx, request_rx) = oneshot:: channel ( ) ;
6684 let request_id = svc. lock ( ) . await . init_request ( & msg, request_tx) . await ?;
@@ -112,6 +130,7 @@ async fn handle<M: ManageDevice + Debug + Send + Sync + 'static, UC: UiControlle
112130 // TODO: Make path and app ID separate.
113131 path_or_app_id,
114132 PortalBackendOptions {
133+ activation_token : activation_token. into ( ) ,
115134 top_origin : top_origin. into ( ) ,
116135 rp_id : Some ( rp_id) . into ( ) ,
117136 } ,
@@ -235,29 +254,32 @@ pub trait CredentialRequestController {
235254 requesting_app : RequestingApplication ,
236255 request : CredentialRequest ,
237256 window_handle : Option < WindowHandle > ,
257+ activation_token : Option < String > ,
238258 ) -> Result < CredentialResponse , WebAuthnError > ;
239259}
240260
241261pub struct CredentialRequestControllerClient {
242- pub initiator : Sender < (
243- CredentialRequest ,
244- RequestingApplication , // Application name sending the request
245- Option < WindowHandle > , // Client window handle,
246- oneshot:: Sender < Result < CredentialResponse , CredentialServiceError > > ,
247- ) > ,
262+ pub initiator : Sender < UiRequestContext > ,
248263}
249264
250265#[ async_trait]
251266impl CredentialRequestController for CredentialRequestControllerClient {
252267 async fn request_credential (
253268 & self ,
254- requesting_app : RequestingApplication ,
269+ app : RequestingApplication ,
255270 request : CredentialRequest ,
256271 window_handle : Option < WindowHandle > ,
272+ activation_token : Option < String > ,
257273 ) -> Result < CredentialResponse , WebAuthnError > {
258274 let ( tx, rx) = oneshot:: channel ( ) ;
259275 self . initiator
260- . send ( ( request, requesting_app, window_handle, tx) )
276+ . send ( UiRequestContext {
277+ request,
278+ app,
279+ window_handle,
280+ activation_token,
281+ response_channel : tx,
282+ } )
261283 . await
262284 . unwrap ( ) ;
263285 let response = rx. await . map_err ( |_| {
0 commit comments