18700: Merge branch 'main'
[arvados.git] / services / api / app / models / api_client.rb
index c9eeaf2669192a9e3178b0c613609dd49d77a6d7..c914051a349685aa5f73dc419a16a17449a4b2f5 100644 (file)
@@ -15,21 +15,34 @@ class ApiClient < ArvadosModel
   end
 
   def is_trusted
-    (from_trusted_url && Rails.configuration.Login.TokenLifetime == 0) || super
+    (from_trusted_url && Rails.configuration.Login.IssueTrustedTokens) || super
   end
 
   protected
 
   def from_trusted_url
     norm_url_prefix = norm(self.url_prefix)
-    norm_url_prefix == norm(Rails.configuration.Services.Workbench1.ExternalURL) or
-      norm_url_prefix == norm(Rails.configuration.Services.Workbench2.ExternalURL) or
-      norm_url_prefix == norm("https://controller.api.client.invalid")
+
+    [Rails.configuration.Services.Workbench1.ExternalURL,
+     Rails.configuration.Services.Workbench2.ExternalURL,
+     "https://controller.api.client.invalid"].each do |url|
+      if norm_url_prefix == norm(url)
+        return true
+      end
+    end
+
+    Rails.configuration.Login.TrustedClients.keys.each do |url|
+      if norm_url_prefix == norm(url)
+        return true
+      end
+    end
+
+    false
   end
 
   def norm url
     # normalize URL for comparison
-    url = URI(url)
+    url = URI(url.to_s)
     if url.scheme == "https"
       url.port == "443"
     end