pub fn stream(
        &self,
    ) -> impl futures::Stream<Item = azure_core::Result<DeviceCodeAuthorization>> + '_ {
        #[derive(Debug, Clone, PartialEq)]
        enum NextState {
            Continue,
            Finish,
        }

        unfold(NextState::Continue, move |state: NextState| async move {
            match state {
                NextState::Continue => {
                    let url = &format!(
                        "https://login.microsoftonline.com/{}/oauth2/v2.0/token",
                        self.tenant_id,
                    );

                    // Throttle down as specified by Azure. This could be
                    // smarter: we could calculate the elapsed time since the
                    // last poll and wait only the delta.
                    new_timer(Duration::from_secs(self.interval)).await;

                    let mut encoded = form_urlencoded::Serializer::new(String::new());
                    let encoded = encoded
                        .append_pair("grant_type", "urn:ietf:params:oauth:grant-type:device_code");
                    let encoded = encoded.append_pair("client_id", self.client_id.as_str());
                    let encoded = encoded.append_pair("device_code", &self.device_code);
                    let encoded = encoded.finish();

                    let http_client = self.http_client.clone().unwrap();

                    match post_form(http_client.clone(), url, encoded).await {
                        Ok(rsp) => {
                            let rsp_status = rsp.status();
                            let rsp_body = rsp.into_body().await;
                            if rsp_status.is_success() {
                                match serde_json::from_slice::<DeviceCodeAuthorization>(&rsp_body) {
                                    Ok(authorization) => {
                                        Some((Ok(authorization), NextState::Finish))
                                    }
                                    Err(error) => {
                                        Some((Err(Error::from(error)), NextState::Finish))
                                    }
                                }
                            } else {
                                match serde_json::from_slice::<DeviceCodeErrorResponse>(&rsp_body) {
                                    Ok(error_rsp) => {
                                        let next_state =
                                            if error_rsp.error == "authorization_pending" {
                                                NextState::Continue
                                            } else {
                                                NextState::Finish
                                            };
                                        Some((
                                            Err(Error::new(ErrorKind::Credential, error_rsp)),
                                            next_state,
                                        ))
                                    }
                                    Err(error) => {
                                        Some((Err(Error::from(error)), NextState::Finish))
                                    }
                                }
                            }
                        }
                        Err(error) => Some((Err(error), NextState::Finish)),
                    }
                }
                NextState::Finish => None,
            }
        })
    }
/// Polls the token endpoint while the user signs in.
/// This will continue until either success or error is returned.
Polls the token endpoint while the user signs in.
This will continue until either success or error is returned.
Polls the token endpoint while the user signs in . This will continue until either success or error is returned .
pub fn stream(
        &self,
    ) -> impl futures::Stream<Item = azure_core::Result<DeviceCodeAuthorization>> + '_ {
        #[derive(Debug, Clone, PartialEq)]
        enum NextState {
            Continue,
            Finish,
        }
        unfold(NextState::Continue, move |state: NextState| async move {
            match state {
                NextState::Continue => {
                    let url = &format!(
                        "https://login.microsoftonline.com/{}/oauth2/v2.0/token",
                        self.tenant_id,
                    );
                    // Throttle down as specified by Azure. This could be
                    // smarter: we could calculate the elapsed time since the
                    // last poll and wait only the delta.
                    new_timer(Duration::from_secs(self.interval)).await;
                    let mut encoded = form_urlencoded::Serializer::new(String::new());
                    let encoded = encoded
                        .append_pair("grant_type", "urn:ietf:params:oauth:grant-type:device_code");
                    let encoded = encoded.append_pair("client_id", self.client_id.as_str());
                    let encoded = encoded.append_pair("device_code", &self.device_code);
                    let encoded = encoded.finish();
                    let http_client = self.http_client.clone().unwrap();
                    match post_form(http_client.clone(), url, encoded).await {
                        Ok(rsp) => {
                            let rsp_status = rsp.status();
                            let rsp_body = rsp.into_body().await;
                            if rsp_status.is_success() {
                                match serde_json::from_slice::<DeviceCodeAuthorization>(&rsp_body) {
                                    Ok(authorization) => {
                                        Some((Ok(authorization), NextState::Finish))
                                    }
                                    Err(error) => {
                                        Some((Err(Error::from(error)), NextState::Finish))
                                    }
                                }
                            } else {
                                match serde_json::from_slice::<DeviceCodeErrorResponse>(&rsp_body) {
                                    Ok(error_rsp) => {
                                        let next_state =
                                            if error_rsp.error == "authorization_pending" {
                                                NextState::Continue
                                            } else {
                                                NextState::Finish
                                            };
                                        Some((
                                            Err(Error::new(ErrorKind::Credential, error_rsp)),
                                            next_state,
                                        ))
                                    }
                                    Err(error) => {
                                        Some((Err(Error::from(error)), NextState::Finish))
                                    }
                                }
                            }
                        }
                        Err(error) => Some((Err(error), NextState::Finish)),
                    }
                }
                NextState::Finish => None,
            }
        })
    }
pub fn stream ( & self , ) -> impl futures :: Stream < Item = azure_core :: Result < DeviceCodeAuthorization > > + ' _ { # [ derive ( Debug Clone PartialEq ) ] enum NextState { Continue , Finish , } unfold ( NextState :: Continue , move | state : NextState | async move { match state { NextState :: Continue => { let url = & format ! ( " " self tenant_id ) ; // Throttle down as specified by Azure. This could be // smarter: we could calculate the elapsed time since the // last poll and wait only the delta. new_timer ( Duration :: from_secs ( self . interval ) ) . await ; let mut encoded = form_urlencoded :: Serializer :: new ( String :: new ( ) ) ; let encoded = encoded . append_pair ( " " , " " ) ; let encoded = encoded . append_pair ( " " , self . client_id . as_str ( ) ) ; let encoded = encoded . append_pair ( " " , & self . device_code ) ; let encoded = encoded . finish ( ) ; let http_client = self . http_client . clone ( ) . unwrap ( ) ; match post_form ( http_client . clone ( ) , url , encoded ) . await { Ok ( rsp ) => { let rsp_status = rsp . status ( ) ; let rsp_body = rsp . into_body ( ) . await ; if rsp_status . is_success ( ) { match serde_json :: from_slice :: < DeviceCodeAuthorization > ( & rsp_body ) { Ok ( authorization ) => { Some ( ( Ok ( authorization ) , NextState :: Finish ) ) } Err ( error ) => { Some ( ( Err ( Error :: from ( error ) ) , NextState :: Finish ) ) } } } else { match serde_json :: from_slice :: < DeviceCodeErrorResponse > ( & rsp_body ) { Ok ( error_rsp ) => { let next_state = if error_rsp . error == " " { NextState :: Continue } else { NextState :: Finish } ; Some ( ( Err ( Error :: new ( ErrorKind :: Credential , error_rsp ) ) , next_state , ) ) } Err ( error ) => { Some ( ( Err ( Error :: from ( error ) ) , NextState :: Finish ) ) } } } } Err ( error ) => Some ( ( Err ( error ) , NextState :: Finish ) ) , } } NextState :: Finish => None , } } ) }
Polls the token endpoint while the user signs in.
Polls the token endpoint while the user signs in .
&self