@@ -103,22 +103,46 @@ public function discover(string $remote, bool $skipCache = false): ICapabilityAw
103103 if ($ this ->config ->getSystemValueBool ('sharing.federation.allowSelfSignedCertificates ' ) === true ) {
104104 $ options ['verify ' ] = false ;
105105 }
106- $ response = $ client ->get ($ remote . '/ocm-provider/ ' , $ options );
107-
108- $ body = null ;
109- if ($ response ->getStatusCode () === Http::STATUS_OK ) {
110- $ body = $ response ->getBody ();
111- // update provider with data returned by the request
112- $ provider ->import (json_decode ($ body , true , 8 , JSON_THROW_ON_ERROR ) ?? []);
113- $ this ->cache ->set ($ remote , $ body , 60 * 60 * 24 );
114- $ this ->remoteProviders [$ remote ] = $ provider ;
115- return $ provider ;
106+ $ urls = [
107+ $ remote . '/.well-known/ocm ' ,
108+ $ remote . '/ocm-provider ' ,
109+ ];
110+
111+
112+ foreach ($ urls as $ url ) {
113+ $ exception = null ;
114+ $ body = null ;
115+ $ status = null ;
116+ try {
117+ $ response = $ client ->get ($ url , $ options );
118+ if ($ response ->getStatusCode () === Http::STATUS_OK ) {
119+ $ body = $ response ->getBody ();
120+ $ status = $ response ->getStatusCode ();
121+ // update provider with data returned by the request
122+ $ provider ->import (json_decode ($ body , true , 8 , JSON_THROW_ON_ERROR ) ?? []);
123+ $ this ->cache ->set ($ remote , $ body , 60 * 60 * 24 );
124+ $ this ->remoteProviders [$ remote ] = $ provider ;
125+ return $ provider ;
126+ }
127+ } catch (\Exception $ e ) {
128+ $ this ->logger ->debug ("Tried unsuccesfully to do discovery at: {$ url }" , [
129+ 'exception ' => $ e ,
130+ 'remote ' => $ remote
131+ ]);
132+ // We want to throw only the last exception
133+ $ exception = $ e ;
134+ continue ;
135+ }
136+ }
137+ if ($ exception ) {
138+ throw $ exception ;
116139 }
117140
141+
118142 throw new OCMProviderException ('invalid remote ocm endpoint ' );
119143 } catch (JsonException |OCMProviderException ) {
120144 $ this ->cache ->set ($ remote , false , 5 * 60 );
121- throw new OCMProviderException ('data returned by remote seems invalid - status: ' . $ response -> getStatusCode ( ) . ' - ' . ($ body ?? '' ));
145+ throw new OCMProviderException ('data returned by remote seems invalid - status: ' . ( $ status ?? '' ) . ' - body: ' . ($ body ?? '' ));
122146 } catch (\Exception $ e ) {
123147 $ this ->cache ->set ($ remote , false , 5 * 60 );
124148 $ this ->logger ->warning ('error while discovering ocm provider ' , [
0 commit comments