@@ -192,16 +192,17 @@ impl UserTokenBuilder {
192
192
pub async fn get_user_token < RE , C , F > (
193
193
self ,
194
194
http_client : C ,
195
- state : Option < & str > ,
196
- code : oauth2:: AuthorizationCode ,
195
+ state : & str ,
196
+ // TODO: Should be either str or AuthorizationCode
197
+ code : & str ,
197
198
) -> Result < UserToken , UserTokenExchangeError < RE > >
198
199
where
199
200
RE : std:: error:: Error + Send + Sync + ' static ,
200
201
C : Copy + FnOnce ( HttpRequest ) -> F ,
201
202
F : Future < Output = Result < HttpResponse , RE > > ,
202
203
{
203
204
if let Some ( csrf) = self . csrf {
204
- if state . is_none ( ) || csrf. secret ( ) != state. expect ( "should not fail" ) {
205
+ if csrf. secret ( ) != state {
205
206
return Err ( UserTokenExchangeError :: StateMismatch ) ;
206
207
}
207
208
} else {
@@ -214,7 +215,7 @@ impl UserTokenBuilder {
214
215
let mut params = HashMap :: new ( ) ;
215
216
params. insert ( "client_id" , self . client_id . as_str ( ) ) ;
216
217
params. insert ( "client_secret" , self . client_secret . secret ( ) . as_str ( ) ) ;
217
- params. insert ( "code" , code. secret ( ) . as_str ( ) ) ;
218
+ params. insert ( "code" , code) ;
218
219
params. insert ( "grant_type" , "authorization_code" ) ;
219
220
params. insert ( "redirect_uri" , self . redirect_url . as_str ( ) ) ;
220
221
let req = HttpRequest {
@@ -278,17 +279,13 @@ mod tests {
278
279
let mut t = UserTokenBuilder :: new (
279
280
ClientId :: new ( "clientid" . to_string ( ) ) ,
280
281
ClientSecret :: new ( "secret" . to_string ( ) ) ,
281
- oauth2 :: RedirectUrl :: new ( r#"https://localhost"# . to_string ( ) ) . unwrap ( ) ,
282
+ crate :: RedirectUrl :: new ( r#"https://localhost"# . to_string ( ) ) . unwrap ( ) ,
282
283
)
283
284
. unwrap ( )
284
285
. force_verify ( true ) ;
285
286
t. csrf = Some ( oauth2:: CsrfToken :: new ( "random" . to_string ( ) ) ) ;
286
287
let token = t
287
- . get_user_token (
288
- crate :: client:: surf_http_client,
289
- Some ( "random" ) ,
290
- oauth2:: AuthorizationCode :: new ( "authcode" . to_string ( ) ) ,
291
- )
288
+ . get_user_token ( crate :: client:: surf_http_client, "random" , "authcode" )
292
289
. await
293
290
. unwrap ( ) ;
294
291
println ! ( "token: {:?} - {}" , token, token. access_token. secret( ) ) ;
0 commit comments