[ARVADOS] created: 1.1.0-166-g1d074df

Git user git at public.curoverse.com
Thu Nov 23 14:10:51 EST 2017


        at  1d074dfeb64d0648255552c94c14f3134e3cd06d (commit)


commit 1d074dfeb64d0648255552c94c14f3134e3cd06d
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Thu Nov 23 13:52:46 2017 -0500

    12627: Use first reader_token as primary token, if no primary given.
    
    Workbench relies on this for anonymous access.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/services/api/app/middlewares/arvados_api_token.rb b/services/api/app/middlewares/arvados_api_token.rb
index 5eb756b..555e661 100644
--- a/services/api/app/middlewares/arvados_api_token.rb
+++ b/services/api/app/middlewares/arvados_api_token.rb
@@ -32,21 +32,29 @@ class ArvadosApiToken
     user = nil
     api_client = nil
     api_client_auth = nil
-    supplied_token =
-      params["api_token"] ||
-      params["oauth_token"] ||
-      env["HTTP_AUTHORIZATION"].andand.match(/OAuth2 ([a-zA-Z0-9]+)/).andand[1]
-    if supplied_token
-      api_client_auth = ApiClientAuthorization.
+    if request.get?
+      reader_tokens = params["reader_tokens"]
+      if reader_tokens.is_a? String
+        reader_tokens = SafeJSON.load(reader_tokens)
+      end
+    else
+      reader_tokens = nil
+    end
+    [params["api_token"],
+     params["oauth_token"],
+     env["HTTP_AUTHORIZATION"].andand.match(/OAuth2 ([a-zA-Z0-9]+)/).andand[1],
+     *reader_tokens,
+    ].each do |supplied|
+      next if !supplied
+      try_auth = ApiClientAuthorization.
         includes(:api_client, :user).
-        where('api_token=? and (expires_at is null or expires_at > CURRENT_TIMESTAMP)', supplied_token).
+        where('api_token=? and (expires_at is null or expires_at > CURRENT_TIMESTAMP)', supplied).
         first
-      if api_client_auth.andand.user
+      if try_auth.andand.user
+        api_client_auth = try_auth
         user = api_client_auth.user
         api_client = api_client_auth.api_client
-      else
-        # Token seems valid, but points to a non-existent (deleted?) user.
-        api_client_auth = nil
+        break
       end
     end
     Thread.current[:api_client_ip_address] = remote_ip
diff --git a/services/api/test/integration/reader_tokens_test.rb b/services/api/test/integration/reader_tokens_test.rb
index 60b06a9..d5dedcd 100644
--- a/services/api/test/integration/reader_tokens_test.rb
+++ b/services/api/test/integration/reader_tokens_test.rb
@@ -53,7 +53,7 @@ class ReaderTokensTest < ActionDispatch::IntegrationTest
       [:to_a, :to_json].each do |formatter|
         test "#{main_auth.inspect} auth with #{formatter} reader token #{read_auth} can't read" do
           get_specimens(main_auth, read_auth)
-          assert_response(if main_auth then 403 else 302 end)
+          assert_response(if main_auth then 403 else 200 end)
         end
 
         test "#{main_auth.inspect} auth with #{formatter} reader token #{read_auth} can't write" do

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list