pub async fn start<'a, 'b, T>(
    http_client: Arc<dyn HttpClient>,
    tenant_id: T,
    client_id: &'a ClientId,
    scopes: &'b [&'b str],
) -> azure_core::Result<DeviceCodePhaseOneResponse<'a>>
where
    T: Into<Cow<'a, str>>,
{
    let tenant_id = tenant_id.into();
    let url = &format!(
        "https://login.microsoftonline.com/{}/oauth2/v2.0/devicecode",
        tenant_id
    );

    let mut encoded = form_urlencoded::Serializer::new(String::new());
    let encoded = encoded.append_pair("client_id", client_id.as_str());
    let encoded = encoded.append_pair("scope", &scopes.join(" "));
    let encoded = encoded.finish();

    let rsp = post_form(http_client.clone(), url, encoded).await?;
    let rsp_status = rsp.status();
    let rsp_body = rsp.into_body().await;
    if !rsp_status.is_success() {
        return Err(
            ErrorKind::http_response_from_body(rsp_status.as_u16(), &rsp_body).into_error(),
        );
    }
    let device_code_response: DeviceCodePhaseOneResponse = serde_json::from_slice(&rsp_body)?;

    // we need to capture some variables that will be useful in
    // the second phase (the client, the tenant_id and the client_id)
    Ok(DeviceCodePhaseOneResponse {
        device_code: device_code_response.device_code,
        user_code: device_code_response.user_code,
        verification_uri: device_code_response.verification_uri,
        expires_in: device_code_response.expires_in,
        interval: device_code_response.interval,
        message: device_code_response.message,
        http_client: Some(http_client),
        tenant_id,
        client_id: client_id.as_str().to_string(),
    })
}
/// Start the device authorization grant flow.
/// The user has only 15 minutes to sign in (the usual value for expires_in).
Start the device authorization grant flow.
The user has only 15 minutes to sign in (the usual value for expires_in).
Start the device authorization grant flow . The user has only 15 minutes to sign in ( the usual value for expires_in ) .
pub async fn start<'a, 'b, T>(
    http_client: Arc<dyn HttpClient>,
    tenant_id: T,
    client_id: &'a ClientId,
    scopes: &'b [&'b str],
) -> azure_core::Result<DeviceCodePhaseOneResponse<'a>>
where
    T: Into<Cow<'a, str>>,
{
    let tenant_id = tenant_id.into();
    let url = &format!(
        "https://login.microsoftonline.com/{}/oauth2/v2.0/devicecode",
        tenant_id
    );
    let mut encoded = form_urlencoded::Serializer::new(String::new());
    let encoded = encoded.append_pair("client_id", client_id.as_str());
    let encoded = encoded.append_pair("scope", &scopes.join(" "));
    let encoded = encoded.finish();
    let rsp = post_form(http_client.clone(), url, encoded).await?;
    let rsp_status = rsp.status();
    let rsp_body = rsp.into_body().await;
    if !rsp_status.is_success() {
        return Err(
            ErrorKind::http_response_from_body(rsp_status.as_u16(), &rsp_body).into_error(),
        );
    }
    let device_code_response: DeviceCodePhaseOneResponse = serde_json::from_slice(&rsp_body)?;
    // we need to capture some variables that will be useful in
    // the second phase (the client, the tenant_id and the client_id)
    Ok(DeviceCodePhaseOneResponse {
        device_code: device_code_response.device_code,
        user_code: device_code_response.user_code,
        verification_uri: device_code_response.verification_uri,
        expires_in: device_code_response.expires_in,
        interval: device_code_response.interval,
        message: device_code_response.message,
        http_client: Some(http_client),
        tenant_id,
        client_id: client_id.as_str().to_string(),
    })
}
pub async fn start < ' a , ' b , T > ( http_client : Arc < dyn HttpClient > , tenant_id : T , client_id : & ' a ClientId , scopes : & ' b [ & ' b str ] , ) -> azure_core :: Result < DeviceCodePhaseOneResponse < ' a > > where T : Into < Cow < ' a , str > > , { let tenant_id = tenant_id . into ( ) ; let url = & format ! ( " " tenant_id ) ; let mut encoded = form_urlencoded :: Serializer :: new ( String :: new ( ) ) ; let encoded = encoded . append_pair ( " " , client_id . as_str ( ) ) ; let encoded = encoded . append_pair ( " " , & scopes . join ( " " ) ) ; let encoded = encoded . finish ( ) ; let rsp = post_form ( http_client . clone ( ) , url , encoded ) . await ? ; let rsp_status = rsp . status ( ) ; let rsp_body = rsp . into_body ( ) . await ; if ! rsp_status . is_success ( ) { return Err ( ErrorKind :: http_response_from_body ( rsp_status . as_u16 ( ) , & rsp_body ) . into_error ( ) , ) ; } let device_code_response : DeviceCodePhaseOneResponse = serde_json :: from_slice ( & rsp_body ) ? ; // we need to capture some variables that will be useful in // the second phase (the client, the tenant_id and the client_id) Ok ( DeviceCodePhaseOneResponse { device_code : device_code_response . device_code , user_code : device_code_response . user_code , verification_uri : device_code_response . verification_uri , expires_in : device_code_response . expires_in , interval : device_code_response . interval , message : device_code_response . message , http_client : Some ( http_client ) , tenant_id , client_id : client_id . as_str ( ) . to_string ( ) , } ) }
Start the device authorization grant flow.
Start the device authorization grant flow .
http_client
Arc<dyn HttpClient>
tenant_id
T
client_id
&'a ClientId
scopes
&'b [&'b str]