17
17
extern crate base64;
18
18
extern crate oauth2;
19
19
extern crate rand;
20
- extern crate url;
21
20
extern crate serde;
21
+ extern crate url;
22
22
23
+ use oauth2:: basic:: { BasicErrorResponse , BasicTokenType } ;
23
24
use oauth2:: TokenType ;
24
- use oauth2:: basic:: { BasicErrorResponse , BasicTokenType } ;
25
25
// Alternatively, this can be `oauth2::curl::http_client` or a custom client.
26
- use oauth2:: reqwest:: http_client;
27
26
use oauth2:: helpers;
27
+ use oauth2:: reqwest:: http_client;
28
28
use oauth2:: {
29
- AccessToken ,
30
- AuthorizationCode ,
31
- AuthUrl ,
32
- Client ,
33
- ClientId ,
34
- ClientSecret ,
35
- CsrfToken ,
36
- EmptyExtraTokenFields ,
37
- ExtraTokenFields ,
38
- RedirectUrl ,
39
- RefreshToken ,
40
- Scope ,
41
- TokenResponse ,
29
+ AccessToken , AuthUrl , AuthorizationCode , Client , ClientId , ClientSecret , CsrfToken ,
30
+ EmptyExtraTokenFields , ExtraTokenFields , RedirectUrl , RefreshToken , Scope , TokenResponse ,
42
31
TokenUrl ,
43
32
} ;
44
33
34
+ use serde:: { Deserialize , Serialize } ;
45
35
use std:: time:: Duration ;
46
- use serde:: { Serialize , Deserialize } ;
47
36
48
37
use std:: env;
49
38
use std:: io:: { BufRead , BufReader , Write } ;
@@ -53,7 +42,7 @@ use url::Url;
53
42
type SpecialTokenResponse = NonStandardTokenResponse < EmptyExtraTokenFields > ;
54
43
type SpecialClient = Client < BasicErrorResponse , SpecialTokenResponse , BasicTokenType > ;
55
44
56
- fn default_token_type ( ) -> Option < BasicTokenType > {
45
+ fn default_token_type ( ) -> Option < BasicTokenType > {
57
46
Some ( BasicTokenType :: Bearer )
58
47
}
59
48
@@ -146,7 +135,7 @@ fn main() {
146
135
. expect ( "Missing the WUNDERLIST_CLIENT_ID environment variable." ) ;
147
136
148
137
let client_secret_str = env:: var ( "WUNDERLIST_CLIENT_SECRET" )
149
- . expect ( "Missing the WUNDERLIST_CLIENT_SECRET environment variable." ) ;
138
+ . expect ( "Missing the WUNDERLIST_CLIENT_SECRET environment variable." ) ;
150
139
151
140
let wunder_client_id = ClientId :: new ( client_id_str. clone ( ) ) ;
152
141
let wunderlist_client_secret = ClientSecret :: new ( client_secret_str. clone ( ) ) ;
@@ -173,9 +162,7 @@ fn main() {
173
162
) ) ;
174
163
175
164
// Generate the authorization URL to which we'll redirect the user.
176
- let ( authorize_url, csrf_state) = client
177
- . authorize_url ( CsrfToken :: new_random)
178
- . url ( ) ;
165
+ let ( authorize_url, csrf_state) = client. authorize_url ( CsrfToken :: new_random) . url ( ) ;
179
166
180
167
println ! (
181
168
"Open this URL in your browser:\n {}\n " ,
@@ -228,20 +215,27 @@ fn main() {
228
215
) ;
229
216
stream. write_all ( response. as_bytes ( ) ) . unwrap ( ) ;
230
217
231
- println ! ( "Wunderlist returned the following code:\n {}\n " , code. secret( ) ) ;
218
+ println ! (
219
+ "Wunderlist returned the following code:\n {}\n " ,
220
+ code. secret( )
221
+ ) ;
232
222
println ! (
233
223
"Wunderlist returned the following state:\n {} (expected `{}`)\n " ,
234
224
state. secret( ) ,
235
225
csrf_state. secret( )
236
226
) ;
237
227
238
228
// Exchange the code with a token.
239
- let token_res = client. exchange_code ( code)
229
+ let token_res = client
230
+ . exchange_code ( code)
240
231
. add_extra_param ( "client_id" , client_id_str)
241
232
. add_extra_param ( "client_secret" , client_secret_str)
242
233
. request ( http_client) ;
243
234
244
- println ! ( "Wunderlist returned the following token:\n {:?}\n " , token_res) ;
235
+ println ! (
236
+ "Wunderlist returned the following token:\n {:?}\n " ,
237
+ token_res
238
+ ) ;
245
239
246
240
break ;
247
241
}
0 commit comments