ssl-hep / ServiceX_App

REST Front End to ServiceX
BSD 3-Clause "New" or "Revised" License
3 stars 10 forks source link

Allow access to protected API endpoints from web sessions #101

Closed AndrewEckart closed 3 years ago

AndrewEckart commented 3 years ago

Currently, one cannot access protected API endpoints from the web frontend, even after signing in with OAuth. An easy test for this is to sign in and then attempt to access the /servicex/transformation route (which would normally return all transformation requests in the database as a JSON list).

This is because the current implementation of the auth_required decorator checks for a JWT access token in the bearer token HTTP header, but the web frontend uses session-based authentication, not token-based authentication.

This PR addresses the issue by checking the is_authenticated flag in the current session object first, before looking for a bearer token in the request. This allows the web frontend to access protected endpoints, so we can now use AJAX to display API data on the website.

codecov[bot] commented 3 years ago

Codecov Report

Merging #101 (0ec19ff) into develop (5678822) will increase coverage by 0.09%. The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #101      +/-   ##
===========================================
+ Coverage    89.39%   89.48%   +0.09%     
===========================================
  Files           46       46              
  Lines         1273     1284      +11     
  Branches       101      104       +3     
===========================================
+ Hits          1138     1149      +11     
  Misses         122      122              
  Partials        13       13              
Impacted Files Coverage Δ
servicex/decorators.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 5678822...0ec19ff. Read the comment docs.