@@ -4,8 +4,8 @@ use azure_sdk_core::errors::AzureError;
44use futures:: stream:: unfold;
55use log:: debug;
66pub use oauth2:: { ClientId , ClientSecret } ;
7+ use std:: borrow:: Cow ;
78use std:: convert:: TryInto ;
8- use std:: sync:: Arc ;
99use std:: time:: Duration ;
1010use url:: form_urlencoded;
1111
@@ -21,7 +21,9 @@ pub struct DeviceCodePhaseOneResponse<'a> {
2121 // from the Azure answer. They will be added
2222 // manually after deserialization
2323 #[ serde( skip) ]
24- tenant_id : & ' a str ,
24+ client : Option < & ' a reqwest:: Client > ,
25+ #[ serde( skip) ]
26+ tenant_id : Cow < ' a , str > ,
2527 // we store the ClientId as string instead of
2628 // the original type because it does not
2729 // implement Default and it's in another
@@ -30,17 +32,22 @@ pub struct DeviceCodePhaseOneResponse<'a> {
3032 client_id : String ,
3133}
3234
33- pub async fn begin_authorize_device_code_flow < ' a , ' b > (
35+ pub async fn begin_authorize_device_code_flow < ' a , ' b , T > (
3436 client : & ' a reqwest:: Client ,
35- tenant_id : & ' a str ,
37+ tenant_id : T ,
3638 client_id : & ' a ClientId ,
3739 scopes : & ' b [ & ' b str ] ,
38- ) -> Result < DeviceCodePhaseOneResponse < ' a > , AzureError > {
40+ ) -> Result < DeviceCodePhaseOneResponse < ' a > , AzureError >
41+ where
42+ T : Into < Cow < ' a , str > > ,
43+ {
3944 let mut encoded = form_urlencoded:: Serializer :: new ( String :: new ( ) ) ;
4045 let encoded = encoded. append_pair ( "client_id" , client_id. as_str ( ) ) ;
4146 let encoded = encoded. append_pair ( "scope" , & scopes. join ( " " ) ) ;
4247 let encoded = encoded. finish ( ) ;
4348
49+ let tenant_id = tenant_id. into ( ) ;
50+
4451 debug ! ( "encoded ==> {}" , encoded) ;
4552
4653 let url = url:: Url :: parse ( & format ! (
@@ -69,6 +76,7 @@ pub async fn begin_authorize_device_code_flow<'a, 'b>(
6976 expires_in : device_code_reponse. expires_in ,
7077 interval : device_code_reponse. interval ,
7178 message : device_code_reponse. message ,
79+ client : Some ( client) ,
7280 tenant_id,
7381 client_id : client_id. as_str ( ) . to_string ( ) ,
7482 } )
@@ -92,7 +100,6 @@ impl<'a> DeviceCodePhaseOneResponse<'a> {
92100
93101 pub fn stream < ' b > (
94102 & ' b self ,
95- client : & ' b reqwest:: Client ,
96103 ) -> impl futures:: Stream < Item = Result < DeviceCodeResponse , DeviceCodeError > > + ' b + ' _ {
97104 #[ derive( Debug , Clone , PartialEq ) ]
98105 enum NextState {
@@ -123,7 +130,9 @@ impl<'a> DeviceCodePhaseOneResponse<'a> {
123130 let encoded = encoded. append_pair ( "device_code" , & self . device_code ) ;
124131 let encoded = encoded. finish ( ) ;
125132
126- let result = match client
133+ let result = match self
134+ . client
135+ . unwrap ( )
127136 . post ( & uri)
128137 . header ( "ContentType" , "application/x-www-form-urlencoded" )
129138 . body ( encoded)
0 commit comments