async fn handle_iotid_get_access_token(
        &self,
        app_config: AppConfig,
        user_profile_id: String,
        refresh_token: String,
        app_scopes: Vec<String>,
        cache_key: AccessTokenKey,
    ) -> TokenManagerResult<Arc<OAuthToken>> {
        let auth_provider_type = &app_config.auth_provider_type;
        let auth_provider_proxy = await!(self.get_auth_provider_proxy(auth_provider_type))?;

        // TODO(ukode): Retrieve the ephemeral credential key from store 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"),
        };

        // TODO(ukode): Create a new attestation signer handle for each request using the device
        // attestation key with better error handling.
        let (_server_chan, client_chan) = zx::Channel::create()
            .token_manager_status(Status::InternalError)
            .expect("Failed to create attestation_signer");
        let attestation_signer = ClientEnd::<AttestationSignerMarker>::new(client_chan);

        // TODO(ukode): Read challenge from cache.
        let mut assertion_jwt_params = AssertionJwtParams {
            credential_eckey: credential_key,
            challenge: Some("".to_string()),
        };

        let (status, updated_credential, access_token, auth_challenge) =
            await!(auth_provider_proxy.get_app_access_token_from_assertion_jwt(
                attestation_signer,
                &mut assertion_jwt_params,
                &refresh_token,
                &mut app_scopes.iter().map(|x| &**x),
            ))
            .map_err(|err| {
                self.discard_auth_provider_proxy(auth_provider_type);
                TokenManagerError::new(Status::AuthProviderServerError).with_cause(err)
            })?;

        match (updated_credential, access_token, auth_challenge) {
            (Some(updated_credential), Some(access_token), Some(_auth_challenge)) => {
                // Store updated_credential in token store
                let db_value = CredentialValue::new(
                    app_config.auth_provider_type,
                    user_profile_id.clone(),
                    updated_credential,
                    None,
                )
                .map_err(|_| Status::AuthProviderServerError)?;

                self.token_store.lock().add_credential(db_value)?;

                // Cache access token
                let native_token = Arc::new(OAuthToken::from(*access_token));
                self.token_cache.lock().put(cache_key, Arc::clone(&native_token));

                // TODO(ukode): Cache auth_challenge
                Ok(native_token)
            }
            _ => Err(TokenManagerError::from(status)),
        }
    }
/// Implements the FIDL TokenManager.GetAccessToken method using an auth provider that supports
/// IoT ID.
Implements the FIDL TokenManager.GetAccessToken method using an auth provider that supports
IoT ID.
Implements the FIDL TokenManager . GetAccessToken method using an auth provider that supports IoT ID .
async fn handle_iotid_get_access_token(
        &self,
        app_config: AppConfig,
        user_profile_id: String,
        refresh_token: String,
        app_scopes: Vec<String>,
        cache_key: AccessTokenKey,
    ) -> TokenManagerResult<Arc<OAuthToken>> {
        let auth_provider_type = &app_config.auth_provider_type;
        let auth_provider_proxy = await!(self.get_auth_provider_proxy(auth_provider_type))?;
        // TODO(ukode): Retrieve the ephemeral credential key from store 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"),
        };
        // TODO(ukode): Create a new attestation signer handle for each request using the device
        // attestation key with better error handling.
        let (_server_chan, client_chan) = zx::Channel::create()
            .token_manager_status(Status::InternalError)
            .expect("Failed to create attestation_signer");
        let attestation_signer = ClientEnd::<AttestationSignerMarker>::new(client_chan);
        // TODO(ukode): Read challenge from cache.
        let mut assertion_jwt_params = AssertionJwtParams {
            credential_eckey: credential_key,
            challenge: Some("".to_string()),
        };
        let (status, updated_credential, access_token, auth_challenge) =
            await!(auth_provider_proxy.get_app_access_token_from_assertion_jwt(
                attestation_signer,
                &mut assertion_jwt_params,
                &refresh_token,
                &mut app_scopes.iter().map(|x| &**x),
            ))
            .map_err(|err| {
                self.discard_auth_provider_proxy(auth_provider_type);
                TokenManagerError::new(Status::AuthProviderServerError).with_cause(err)
            })?;
        match (updated_credential, access_token, auth_challenge) {
            (Some(updated_credential), Some(access_token), Some(_auth_challenge)) => {
                // Store updated_credential in token store
                let db_value = CredentialValue::new(
                    app_config.auth_provider_type,
                    user_profile_id.clone(),
                    updated_credential,
                    None,
                )
                .map_err(|_| Status::AuthProviderServerError)?;
                self.token_store.lock().add_credential(db_value)?;
                // Cache access token
                let native_token = Arc::new(OAuthToken::from(*access_token));
                self.token_cache.lock().put(cache_key, Arc::clone(&native_token));
                // TODO(ukode): Cache auth_challenge
                Ok(native_token)
            }
            _ => Err(TokenManagerError::from(status)),
        }
    }
async fn handle_iotid_get_access_token ( & self , app_config : AppConfig , user_profile_id : String , refresh_token : String , app_scopes : Vec < String > , cache_key : AccessTokenKey , ) -> TokenManagerResult < Arc < OAuthToken > > { let auth_provider_type = & app_config . auth_provider_type ; let auth_provider_proxy = await ! ( self get_auth_provider_proxy ( auth_provider_type ) ) ? ; // TODO(ukode): Retrieve the ephemeral credential key from store 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 ( " " ) , } ; // TODO(ukode): Create a new attestation signer handle for each request using the device // attestation key with better error handling. let ( _server_chan , client_chan ) = zx :: Channel :: create ( ) . token_manager_status ( Status :: InternalError ) . expect ( " " ) ; let attestation_signer = ClientEnd :: < AttestationSignerMarker > :: new ( client_chan ) ; // TODO(ukode): Read challenge from cache. let mut assertion_jwt_params = AssertionJwtParams { credential_eckey : credential_key , challenge : Some ( " " . to_string ( ) ) , } ; let ( status , updated_credential , access_token , auth_challenge ) = await ! ( auth_provider_proxy get_app_access_token_from_assertion_jwt ( attestation_signer mut assertion_jwt_params refresh_token mut app_scopes iter ( ) map ( x x ) ) ) . map_err ( | err | { self . discard_auth_provider_proxy ( auth_provider_type ) ; TokenManagerError :: new ( Status :: AuthProviderServerError ) . with_cause ( err ) } ) ? ; match ( updated_credential , access_token , auth_challenge ) { ( Some ( updated_credential ) , Some ( access_token ) , Some ( _auth_challenge ) ) => { // Store updated_credential in token store let db_value = CredentialValue :: new ( app_config . auth_provider_type , user_profile_id . clone ( ) , updated_credential , None , ) . map_err ( | _ | Status :: AuthProviderServerError ) ? ; self . token_store . lock ( ) . add_credential ( db_value ) ? ; // Cache access token let native_token = Arc :: new ( OAuthToken :: from ( * access_token ) ) ; self . token_cache . lock ( ) . put ( cache_key , Arc :: clone ( & native_token ) ) ; // TODO(ukode): Cache auth_challenge Ok ( native_token ) } _ => Err ( TokenManagerError :: from ( status ) ) , } }
Implements the FIDL TokenManager.GetAccessToken method using an auth provider that supports
IoT ID.
Implements the FIDL TokenManager . GetAccessToken method using an auth provider that supports IoT ID .
&self
app_config
AppConfig
user_profile_id
String
refresh_token
String
app_scopes
Vec<String>
cache_key
AccessTokenKey
&self
app_config
AppConfig
user_profile_id
String
refresh_token
String
app_scopes
Vec<String>
cache_key
AccessTokenKey