@@ -524,14 +524,14 @@ impl Account {
524
524
pub async fn from_parts (
525
525
id : String ,
526
526
key_pkcs8_der : & [ u8 ] ,
527
- directory_url : & str ,
527
+ server_url : String ,
528
528
http : Box < dyn HttpClient > ,
529
529
) -> Result < Self , Error > {
530
530
Ok ( Self {
531
531
inner : Arc :: new ( AccountInner {
532
532
id,
533
533
key : Key :: from_pkcs8_der ( key_pkcs8_der) ?,
534
- client : Arc :: new ( Client :: new ( directory_url , http) . await ?) ,
534
+ client : Arc :: new ( Client :: new ( server_url , http) . await ?) ,
535
535
} ) ,
536
536
} )
537
537
}
@@ -543,14 +543,13 @@ impl Account {
543
543
#[ cfg( feature = "hyper-rustls" ) ]
544
544
pub async fn create (
545
545
account : & NewAccount < ' _ > ,
546
- server_url : & str ,
546
+ server_url : String ,
547
547
external_account : Option < & ExternalAccountKey > ,
548
548
) -> Result < ( Account , AccountCredentials ) , Error > {
549
549
Self :: create_inner (
550
550
account,
551
551
external_account,
552
552
Client :: new ( server_url, Box :: new ( DefaultClient :: try_new ( ) ?) ) . await ?,
553
- server_url,
554
553
)
555
554
. await
556
555
}
@@ -561,15 +560,14 @@ impl Account {
561
560
/// Use [`Account::from_credentials()`] to restore the account from the credentials.
562
561
pub async fn create_with_http (
563
562
account : & NewAccount < ' _ > ,
564
- server_url : & str ,
563
+ server_url : String ,
565
564
external_account : Option < & ExternalAccountKey > ,
566
565
http : Box < dyn HttpClient > ,
567
566
) -> Result < ( Account , AccountCredentials ) , Error > {
568
567
Self :: create_inner (
569
568
account,
570
569
external_account,
571
570
Client :: new ( server_url, http) . await ?,
572
- server_url,
573
571
)
574
572
. await
575
573
}
@@ -578,7 +576,6 @@ impl Account {
578
576
account : & NewAccount < ' _ > ,
579
577
external_account : Option < & ExternalAccountKey > ,
580
578
client : Client ,
581
- server_url : & str ,
582
579
) -> Result < ( Account , AccountCredentials ) , Error > {
583
580
let ( key, key_pkcs8) = Key :: generate ( ) ?;
584
581
let payload = NewAccountPayload {
@@ -611,7 +608,7 @@ impl Account {
611
608
let credentials = AccountCredentials {
612
609
id : id. clone ( ) ,
613
610
key_pkcs8 : key_pkcs8. as_ref ( ) . to_vec ( ) ,
614
- directory : Some ( server_url. to_owned ( ) ) ,
611
+ directory : Some ( client . server_url . clone ( ) . unwrap ( ) ) , // New clients always have `server_url`
615
612
// We support deserializing URLs for compatibility with versions pre 0.4,
616
613
// but we prefer to get fresh URLs from the `server_url` for newer credentials.
617
614
urls : None ,
@@ -881,8 +878,12 @@ impl AccountInner {
881
878
id : credentials. id ,
882
879
key : Key :: from_pkcs8_der ( credentials. key_pkcs8 . as_ref ( ) ) ?,
883
880
client : Arc :: new ( match ( credentials. directory , credentials. urls ) {
884
- ( Some ( server_url) , _) => Client :: new ( & server_url, http) . await ?,
885
- ( None , Some ( directory) ) => Client { http, directory } ,
881
+ ( Some ( server_url) , _) => Client :: new ( server_url, http) . await ?,
882
+ ( None , Some ( directory) ) => Client {
883
+ http,
884
+ directory,
885
+ server_url : None ,
886
+ } ,
886
887
( None , None ) => return Err ( "no server URLs found" . into ( ) ) ,
887
888
} ) ,
888
889
} )
@@ -929,19 +930,21 @@ impl Signer for AccountInner {
929
930
struct Client {
930
931
http : Box < dyn HttpClient > ,
931
932
directory : Directory ,
933
+ server_url : Option < String > ,
932
934
}
933
935
934
936
impl Client {
935
- async fn new ( server_url : & str , http : Box < dyn HttpClient > ) -> Result < Self , Error > {
937
+ async fn new ( server_url : String , http : Box < dyn HttpClient > ) -> Result < Self , Error > {
936
938
let req = Request :: builder ( )
937
- . uri ( server_url)
939
+ . uri ( & server_url)
938
940
. body ( Full :: default ( ) )
939
941
. expect ( "infallible error should not occur" ) ;
940
942
let rsp = http. request ( req) . await ?;
941
943
let body = rsp. body ( ) . await . map_err ( Error :: Other ) ?;
942
944
Ok ( Client {
943
945
http,
944
946
directory : serde_json:: from_slice ( & body) ?,
947
+ server_url : Some ( server_url) ,
945
948
} )
946
949
}
947
950
0 commit comments