@@ -33,11 +33,7 @@ pub struct DeviceFlow {
3333
3434impl DeviceFlow {
3535 /// Creates a new `DeviceFlow` instance.
36- pub fn new (
37- client_id : String ,
38- device_authorization_url : String ,
39- token_url : String ,
40- ) -> Self {
36+ pub fn new ( client_id : String , device_authorization_url : String , token_url : String ) -> Self {
4137 Self {
4238 client_id,
4339 device_authorization_url,
@@ -59,10 +55,7 @@ impl DeviceFlow {
5955 . http_client
6056 . post ( & self . device_authorization_url )
6157 . header ( "Accept" , "application/json" )
62- . form ( & [
63- ( "client_id" , & self . client_id ) ,
64- ( "scope" , & scope_param) ,
65- ] )
58+ . form ( & [ ( "client_id" , & self . client_id ) , ( "scope" , & scope_param) ] )
6659 . send ( )
6760 . await
6861 . map_err ( |_| AuthError :: Network ) ?;
@@ -78,7 +71,12 @@ impl DeviceFlow {
7871 response
7972 . json :: < DeviceAuthorizationResponse > ( )
8073 . await
81- . map_err ( |e| AuthError :: Provider ( format ! ( "Failed to parse device authorization response: {}" , e) ) )
74+ . map_err ( |e| {
75+ AuthError :: Provider ( format ! (
76+ "Failed to parse device authorization response: {}" ,
77+ e
78+ ) )
79+ } )
8280 }
8381
8482 /// Polls the token endpoint until an access token is granted or an error occurs.
@@ -99,25 +97,27 @@ impl DeviceFlow {
9997 . form ( & [
10098 ( "client_id" , & self . client_id ) ,
10199 ( "device_code" , & device_code. to_string ( ) ) ,
102- ( "grant_type" , & "urn:ietf:params:oauth:grant-type:device_code" . to_string ( ) ) ,
100+ (
101+ "grant_type" ,
102+ & "urn:ietf:params:oauth:grant-type:device_code" . to_string ( ) ,
103+ ) ,
103104 ] )
104105 . send ( )
105106 . await
106107 . map_err ( |_| AuthError :: Network ) ?;
107108
108109 let status = response. status ( ) ;
109-
110+
110111 if status. is_success ( ) {
111- return response
112- . json :: < OAuthToken > ( )
113- . await
114- . map_err ( |e| AuthError :: Provider ( format ! ( "Failed to parse token response: {}" , e) ) ) ;
112+ return response. json :: < OAuthToken > ( ) . await . map_err ( |e| {
113+ AuthError :: Provider ( format ! ( "Failed to parse token response: {}" , e) )
114+ } ) ;
115115 } else {
116116 let error_resp: serde_json:: Value = response
117117 . json ( )
118118 . await
119119 . map_err ( |_| AuthError :: Provider ( "Failed to parse error response" . into ( ) ) ) ?;
120-
120+
121121 let error = error_resp[ "error" ] . as_str ( ) . unwrap_or ( "unknown_error" ) ;
122122
123123 match error {
@@ -134,7 +134,10 @@ impl DeviceFlow {
134134 return Err ( AuthError :: Provider ( "Device code expired" . into ( ) ) ) ;
135135 }
136136 _ => {
137- return Err ( AuthError :: Provider ( format ! ( "Token polling failed: {}" , error) ) ) ;
137+ return Err ( AuthError :: Provider ( format ! (
138+ "Token polling failed: {}" ,
139+ error
140+ ) ) ) ;
138141 }
139142 }
140143 }
0 commit comments