/// Implements the FIDL TokenManager.Authorize method using an AuthProvider that supports
/// IoT ID.
Implements the FIDL TokenManager.Authorize method using an AuthProvider that supports
IoT ID.
Implements the FIDL TokenManager . Authorize method using an AuthProvider that supports IoT ID .
async fn handle_iotid_authorize<'a>(
        &'a self,
        context: &'a TokenManagerContext,
        app_config: AppConfig,
        user_profile_id: Option<String>,
        _app_scopes: Vec<String>,
        auth_code: Option<String>,
    ) -> TokenManagerResult<UserProfileInfo> {
        let auth_provider_type = &app_config.auth_provider_type;
        let auth_provider_proxy = await!(self.get_auth_provider_proxy(auth_provider_type))?;
        let (ui_context_client_end, ui_context_server_end) =
            create_endpoints().token_manager_status(Status::UnknownError)?;
        context
            .auth_ui_context_provider
            .get_authentication_ui_context(ui_context_server_end)
            .token_manager_status(Status::InvalidAuthContext)?;
        // TODO(ukode): Create a new attestation signer handle for each request using the device
        // attestation key with better error handling.
        let (attestation_signer_client_end, _) =
            create_endpoints().token_manager_status(Status::UnknownError)?;
        // TODO(ukode): Add product root certificates and device attestation certificate to this
        // certificate chain.
        let certificate_chain = Vec::<String>::new();
        // TODO(ukode): Create an ephemeral credential key and add the public key params here.
        let credential_key = CredentialEcKey {
            curve: String::from("P-256"),
            key_x_val: String::from("TODO"),
            key_y_val: String::from("TODO"),
            fingerprint_sha_256: String::from("TODO"),
        };
        let mut attestation_jwt_params = AttestationJwtParams {
            credential_eckey: credential_key,
            certificate_chain: certificate_chain,
            auth_code: auth_code.unwrap_or("".to_string()),
        };
        let (status, credential, _access_token, auth_challenge, user_profile_info) =
            await!(auth_provider_proxy.get_persistent_credential_from_attestation_jwt(
                attestation_signer_client_end,
                &mut attestation_jwt_params,
                Some(ui_context_client_end),
                user_profile_id.as_ref().map(|x| &**x),
            ))
            .map_err(|err| {
                self.discard_auth_provider_proxy(auth_provider_type);
                TokenManagerError::new(Status::AuthProviderServerError).with_cause(err)
            })?;
        match (credential, auth_challenge, user_profile_info) {
            (Some(credential), Some(_auth_challenge), Some(user_profile_info)) => {
                // Store persistent credential
                let db_value = CredentialValue::new(
                    app_config.auth_provider_type,
                    user_profile_info.id.clone(),
                    credential,
                    None,
                )
                .map_err(|_| Status::AuthProviderServerError)?;
                self.token_store.lock().add_credential(db_value)?;
                // TODO(ukode): Store credential keys
                // TODO(ukode): Cache auth_challenge
                Ok(*user_profile_info)
            }
            _ => Err(TokenManagerError::from(status)),
        }
    }
async fn handle_iotid_authorize < ' a > ( & ' a self , context : & ' a TokenManagerContext , app_config : AppConfig , user_profile_id : Option < String > , _app_scopes : Vec < String > , auth_code : Option < String > , ) -> TokenManagerResult < UserProfileInfo > { let auth_provider_type = & app_config . auth_provider_type ; let auth_provider_proxy = await ! ( self get_auth_provider_proxy ( auth_provider_type ) ) ? ; let ( ui_context_client_end , ui_context_server_end ) = create_endpoints ( ) . token_manager_status ( Status :: UnknownError ) ? ; context . auth_ui_context_provider . get_authentication_ui_context ( ui_context_server_end ) . token_manager_status ( Status :: InvalidAuthContext ) ? ; // TODO(ukode): Create a new attestation signer handle for each request using the device // attestation key with better error handling. let ( attestation_signer_client_end , _ ) = create_endpoints ( ) . token_manager_status ( Status :: UnknownError ) ? ; // TODO(ukode): Add product root certificates and device attestation certificate to this // certificate chain. let certificate_chain = Vec :: < String > :: new ( ) ; // TODO(ukode): Create an ephemeral credential key and add the public key params here. let credential_key = CredentialEcKey { curve : String :: from ( " " ) , key_x_val : String :: from ( " " ) , key_y_val : String :: from ( " " ) , fingerprint_sha_256 : String :: from ( " " ) , } ; let mut attestation_jwt_params = AttestationJwtParams { credential_eckey : credential_key , certificate_chain : certificate_chain , auth_code : auth_code . unwrap_or ( " " . to_string ( ) ) , } ; let ( status , credential , _access_token , auth_challenge , user_profile_info ) = await ! ( auth_provider_proxy get_persistent_credential_from_attestation_jwt ( attestation_signer_client_end mut attestation_jwt_params Some ( ui_context_client_end ) user_profile_id as_ref ( ) map ( x x ) ) ) . map_err ( | err | { self . discard_auth_provider_proxy ( auth_provider_type ) ; TokenManagerError :: new ( Status :: AuthProviderServerError ) . with_cause ( err ) } ) ? ; match ( credential , auth_challenge , user_profile_info ) { ( Some ( credential ) , Some ( _auth_challenge ) , Some ( user_profile_info ) ) => { // Store persistent credential let db_value = CredentialValue :: new ( app_config . auth_provider_type , user_profile_info . id . clone ( ) , credential , None , ) . map_err ( | _ | Status :: AuthProviderServerError ) ? ; self . token_store . lock ( ) . add_credential ( db_value ) ? ; // TODO(ukode): Store credential keys // TODO(ukode): Cache auth_challenge Ok ( * user_profile_info ) } _ => Err ( TokenManagerError :: from ( status ) ) , } }
Implements the FIDL TokenManager.Authorize method using an AuthProvider that supports
IoT ID.
Implements the FIDL TokenManager . Authorize method using an AuthProvider that supports IoT ID .
&'a self
context
&'a TokenManagerContext
app_config
AppConfig
user_profile_id
Option<String>
_app_scopes
Vec<String>
auth_code
Option<String>