@@ -138,8 +138,6 @@ async fn authenticate_stream_inner(
138
138
// &server_first.server_nonce,
139
139
// )?;
140
140
141
- // dbg!("authorization header: {}", &authorization_header);
142
-
143
141
// let mut client_second_payload = doc! {
144
142
// "a": authorization_header,
145
143
// "d": date.format(AWS_LONG_DATE_FMT).to_string(),
@@ -149,23 +147,14 @@ async fn authenticate_stream_inner(
149
147
// client_second_payload.insert("t", security_token);
150
148
// }
151
149
152
- let sigv4_headers = compute_aws_sigv4_headers (
150
+ let client_second_payload = compute_aws_sigv4_payload (
153
151
creds,
154
152
date,
155
153
& server_first. sts_host ,
156
154
& server_first. server_nonce ,
157
155
)
158
156
. await ?;
159
157
160
- let mut client_second_payload = doc ! {
161
- "a" : sigv4_headers. authorization,
162
- "d" : sigv4_headers. date,
163
- } ;
164
-
165
- if let Some ( token) = sigv4_headers. token {
166
- client_second_payload. insert ( "t" , token) ;
167
- }
168
-
169
158
let client_second_payload_bytes = client_second_payload. encode_to_vec ( ) ?;
170
159
171
160
let sasl_continue = SaslContinue :: new (
@@ -226,18 +215,12 @@ pub(crate) async fn get_aws_credentials(credential: &Credential) -> Result<Crede
226
215
}
227
216
}
228
217
229
- pub struct AwsSigV4Headers {
230
- pub authorization : String ,
231
- pub date : String ,
232
- pub token : Option < String > ,
233
- }
234
-
235
- pub async fn compute_aws_sigv4_headers (
218
+ pub async fn compute_aws_sigv4_payload (
236
219
creds : Credentials ,
237
220
date : DateTime < Utc > ,
238
221
host : & str ,
239
222
server_nonce : & [ u8 ] ,
240
- ) -> Result < AwsSigV4Headers > {
223
+ ) -> Result < Document > {
241
224
let date_str = date. format ( "%Y%m%dT%H%M%SZ" ) . to_string ( ) ;
242
225
243
226
let region = if host == "sts.amazonaws.com" {
@@ -260,9 +243,9 @@ pub async fn compute_aws_sigv4_headers(
260
243
. header ( "host" , host)
261
244
. header ( "content-type" , "application/x-www-form-urlencoded" )
262
245
. header ( "content-length" , body_bytes. len ( ) )
263
- . header ( "x-amz-date" , date_str. clone ( ) )
246
+ . header ( "x-amz-date" , & date_str)
264
247
. header ( "x-mongodb-gs2-cb-flag" , "n" )
265
- . header ( "x-mongodb-server-nonce" , nonce_b64. clone ( ) ) ;
248
+ . header ( "x-mongodb-server-nonce" , & nonce_b64) ;
266
249
267
250
if let Some ( token) = creds. session_token ( ) {
268
251
builder = builder. header ( "x-amz-security-token" , token) ;
@@ -307,33 +290,35 @@ pub async fn compute_aws_sigv4_headers(
307
290
. into_parts ( ) ;
308
291
309
292
signing_instructions. apply_to_request_http1x ( & mut request) ;
310
- dbg ! ( "ending computation part of compute_aws_sigv4_headers" ) ;
311
293
312
294
// Extract the Authorization header
313
295
let headers = request. headers ( ) ;
314
- let authorization = headers
296
+ let authorization_header = headers
315
297
. get ( "authorization" )
316
298
. ok_or_else ( || Error :: authentication_error ( MECH_NAME , "Missing authorization header" ) ) ?
317
299
. to_str ( )
318
300
. map_err ( |e| Error :: authentication_error ( MECH_NAME , & format ! ( "Invalid header value: {e}" ) ) ) ?
319
301
. to_string ( ) ;
320
- dbg ! ( "authorization header: {}" , & authorization) ;
321
302
322
- let token = headers
303
+ let token_header = headers
323
304
. get ( "x-amz-security-token" )
324
305
. map ( |v| {
325
306
v. to_str ( ) . map ( |s| s. to_string ( ) ) . map_err ( |e| {
326
307
Error :: authentication_error ( MECH_NAME , & format ! ( "Invalid token header: {e}" ) )
327
308
} )
328
309
} )
329
310
. transpose ( ) ?;
330
- dbg ! ( "token header: {}" , & token) ;
331
311
332
- Ok ( AwsSigV4Headers {
333
- authorization,
334
- date : date_str,
335
- token,
336
- } )
312
+ let mut payload = doc ! {
313
+ "a" : authorization_header,
314
+ "d" : date_str,
315
+ } ;
316
+
317
+ if let Some ( token) = token_header {
318
+ payload. insert ( "t" , token) ;
319
+ }
320
+
321
+ Ok ( payload)
337
322
}
338
323
339
324
/// Contains the credentials for MONGODB-AWS authentication.
0 commit comments