// Attach a service provider account to this Fuchsia account
Attach a service provider account to this Fuchsia account
Attach a service provider account to this Fuchsia account
async fn add_service_provider_account(
        auth_context_provider: ClientEnd<AuthenticationContextProviderMarker>,
        auth_provider_type: String,
        account_handler: Arc<AccountHandlerConnection>,
    ) -> Result<UserProfileInfo, AccountManagerError> {
        // Use account handler to get a channel to the account
        let (account_client_end, account_server_end) =
            create_endpoints().account_manager_status(Status::IoError)?;
        match await!(account_handler.proxy().get_account(auth_context_provider, account_server_end))
        {
            Ok(Status::Ok) => Ok(()),
            Ok(status) => Err(AccountManagerError::new(status)),
            Err(err) => Err(AccountManagerError::new(Status::IoError).with_cause(err)),
        }?;
        let account_proxy =
            account_client_end.into_proxy().account_manager_status(Status::IoError)?;
        // Use the account to get the persona
        let (persona_client_end, persona_server_end) =
            create_endpoints().account_manager_status(Status::IoError)?;
        match await!(account_proxy.get_default_persona(persona_server_end)) {
            Ok((Status::Ok, _)) => Ok(()),
            Ok((status, _)) => Err(AccountManagerError::new(status)),
            Err(err) => Err(AccountManagerError::new(Status::IoError).with_cause(err)),
        }?;
        let persona_proxy =
            persona_client_end.into_proxy().account_manager_status(Status::IoError)?;
        // Use the persona to get the token manager
        let (tm_client_end, tm_server_end) =
            create_endpoints().account_manager_status(Status::IoError)?;
        match await!(persona_proxy.get_token_manager(SELF_URL, tm_server_end)) {
            Ok(Status::Ok) => Ok(()),
            Ok(status) => Err(AccountManagerError::new(status)),
            Err(err) => Err(AccountManagerError::new(Status::IoError).with_cause(err)),
        }?;
        let tm_proxy = tm_client_end.into_proxy().account_manager_status(Status::IoError)?;
        // Use the token manager to authorize
        let mut app_config = AppConfig {
            auth_provider_type,
            client_id: None,
            client_secret: None,
            redirect_uri: None,
        };
        match await!(tm_proxy.authorize(
            &mut app_config,
            None, /* auth_ui_context */
            &mut APP_SCOPES.iter().map(|x| &**x),
            None, /* user_profile_id */
            None, /* auth_code */
        )) {
            Ok((AuthStatus::Ok, None)) => Err(AccountManagerError::new(Status::InternalError)
                .with_cause(format_err!("Invalid response from token manager"))),
            Ok((AuthStatus::Ok, Some(user_profile))) => Ok(*user_profile),
            Ok((status, _)) => Err(AccountManagerError::from(status)),
            Err(err) => Err(AccountManagerError::new(Status::IoError).with_cause(err)),
        }
    }
async fn add_service_provider_account ( auth_context_provider : ClientEnd < AuthenticationContextProviderMarker > , auth_provider_type : String , account_handler : Arc < AccountHandlerConnection > , ) -> Result < UserProfileInfo , AccountManagerError > { // Use account handler to get a channel to the account let ( account_client_end , account_server_end ) = create_endpoints ( ) . account_manager_status ( Status :: IoError ) ? ; match await ! ( account_handler proxy ( ) get_account ( auth_context_provider account_server_end ) ) { Ok ( Status :: Ok ) => Ok ( ( ) ) , Ok ( status ) => Err ( AccountManagerError :: new ( status ) ) , Err ( err ) => Err ( AccountManagerError :: new ( Status :: IoError ) . with_cause ( err ) ) , } ? ; let account_proxy = account_client_end . into_proxy ( ) . account_manager_status ( Status :: IoError ) ? ; // Use the account to get the persona let ( persona_client_end , persona_server_end ) = create_endpoints ( ) . account_manager_status ( Status :: IoError ) ? ; match await ! ( account_proxy get_default_persona ( persona_server_end ) ) { Ok ( ( Status :: Ok , _ ) ) => Ok ( ( ) ) , Ok ( ( status , _ ) ) => Err ( AccountManagerError :: new ( status ) ) , Err ( err ) => Err ( AccountManagerError :: new ( Status :: IoError ) . with_cause ( err ) ) , } ? ; let persona_proxy = persona_client_end . into_proxy ( ) . account_manager_status ( Status :: IoError ) ? ; // Use the persona to get the token manager let ( tm_client_end , tm_server_end ) = create_endpoints ( ) . account_manager_status ( Status :: IoError ) ? ; match await ! ( persona_proxy get_token_manager ( SELF_URL tm_server_end ) ) { Ok ( Status :: Ok ) => Ok ( ( ) ) , Ok ( status ) => Err ( AccountManagerError :: new ( status ) ) , Err ( err ) => Err ( AccountManagerError :: new ( Status :: IoError ) . with_cause ( err ) ) , } ? ; let tm_proxy = tm_client_end . into_proxy ( ) . account_manager_status ( Status :: IoError ) ? ; // Use the token manager to authorize let mut app_config = AppConfig { auth_provider_type , client_id : None , client_secret : None , redirect_uri : None , } ; match await ! ( tm_proxy authorize ( mut app_config None /* auth_ui_context */ mut APP_SCOPES iter ( ) map ( x x ) None /* user_profile_id */ None /* auth_code */ ) ) { Ok ( ( AuthStatus :: Ok , None ) ) => Err ( AccountManagerError :: new ( Status :: InternalError ) . with_cause ( format_err ! ( " " ) ) ) , Ok ( ( AuthStatus :: Ok , Some ( user_profile ) ) ) => Ok ( * user_profile ) , Ok ( ( status , _ ) ) => Err ( AccountManagerError :: from ( status ) ) , Err ( err ) => Err ( AccountManagerError :: new ( Status :: IoError ) . with_cause ( err ) ) , } }
Attach a service provider account to this Fuchsia account
Attach a service provider account to this Fuchsia account
auth_context_provider
ClientEnd<AuthenticationContextProviderMarker>
auth_provider_type
String
account_handler
Arc<AccountHandlerConnection>