- 
                Notifications
    
You must be signed in to change notification settings  - Fork 32
 
🐛 Fixes auth product error in vendor services 🚨 #6512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            pcrespov
  merged 25 commits into
  ITISFoundation:master
from
pcrespov:is6506/fix-auth-product
  
      
      
   
  Oct 14, 2024 
      
    
  
     Merged
                    Changes from 23 commits
      Commits
    
    
            Show all changes
          
          
            25 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      a064baa
              
                updates tests
              
              
                pcrespov b982db7
              
                adds header with produc tname
              
              
                pcrespov b8ddfb4
              
                refactor
              
              
                pcrespov e3c210f
              
                info
              
              
                pcrespov c703eb4
              
                robust module
              
              
                pcrespov 4e0d39f
              
                cleanup
              
              
                pcrespov 85c779c
              
                cleanup permission key
              
              
                pcrespov 2c3cc82
              
                removes default product to avoid accidental cross-product login
              
              
                pcrespov 8e98d4c
              
                minor
              
              
                pcrespov 5d2c037
              
                tests
              
              
                pcrespov 2bd0f5d
              
                fixes key
              
              
                pcrespov 4538a06
              
                checks XForeward-host
              
              
                pcrespov 8780e8d
              
                fixes tabs
              
              
                pcrespov a73e6a6
              
                fixes import
              
              
                pcrespov 795dbc0
              
                rm undefined and default product
              
              
                pcrespov 9d07414
              
                defaults
              
              
                pcrespov 808dea9
              
                undo headers to avoid CORS block
              
              
                pcrespov 42ae57d
              
                rm default
              
              
                pcrespov 33cbebd
              
                adds warning
              
              
                pcrespov 2d4b300
              
                bad import
              
              
                pcrespov 157cc6d
              
                fixes test
              
              
                pcrespov 194f5cc
              
                log
              
              
                pcrespov 74088cb
              
                default app
              
              
                pcrespov 8be5c43
              
                @GitHK review: session
              
              
                pcrespov ab71c65
              
                @GitHK review: rm header
              
              
                pcrespov File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            2 changes: 2 additions & 0 deletions
          
          2 
        
  services/web/server/src/simcore_service_webserver/security/_constants.py
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| from typing import Final | ||
| 
     | 
||
| MSG_AUTH_NOT_AVAILABLE: Final[str] = "Authentication service is temporary unavailable" | ||
| 
     | 
||
| PERMISSION_PRODUCT_LOGIN_KEY: Final[str] = "product.login" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            72 changes: 72 additions & 0 deletions
          
          72 
        
  services/web/server/src/simcore_service_webserver/session/_cookie_storage.py
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """ | ||
| Extends aiohttp_session.cookie_storage | ||
| """ | ||
| 
     | 
||
| import logging | ||
| import time | ||
| 
     | 
||
| import aiohttp_session | ||
| from aiohttp import web | ||
| from aiohttp_session.cookie_storage import EncryptedCookieStorage | ||
| 
     | 
||
| _logger = logging.getLogger(__name__) | ||
| 
     | 
||
| 
     | 
||
| def _share_cookie_across_all_subdomains( | ||
| request: web.BaseRequest, params: aiohttp_session._CookieParams | ||
| ) -> aiohttp_session._CookieParams: | ||
| """ | ||
| Shares cookie across all subdomains, by appending a dot (`.`) in front of the domain name | ||
| overwrite domain from `None` (browser sets `example.com`) to `.example.com` | ||
| """ | ||
| if (host := request.url.host) and host is not None: | ||
| params["domain"] = f".{host.lstrip('.')}" | ||
                
      
                  pcrespov marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| return params | ||
| 
     | 
||
| 
     | 
||
| class SharedCookieEncryptedCookieStorage(EncryptedCookieStorage): | ||
| async def save_session( | ||
| self, | ||
| request: web.Request, | ||
| response: web.StreamResponse, | ||
| session: aiohttp_session.Session, | ||
| ) -> None: | ||
| # link response to originating request (allows to detect the orginal request url) | ||
| response._req = request # pylint:disable=protected-access # noqa: SLF001 | ||
| 
     | 
||
| await super().save_session(request, response, session) | ||
| 
     | 
||
| def save_cookie( | ||
| self, | ||
| response: web.StreamResponse, | ||
| cookie_data: str, | ||
| *, | ||
| max_age: int | None = None, | ||
| ) -> None: | ||
| 
     | 
||
| params = self._cookie_params.copy() | ||
| if request := response._req: # pylint:disable=protected-access # noqa: SLF001 | ||
| params = _share_cookie_across_all_subdomains(request, params) | ||
                
      
                  pcrespov marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| # -------------------------------------------------------- | ||
| # WARNING: the code below is taken and adapted from the superclass | ||
| # implementation `EncryptedCookieStorage.save_cookie` | ||
| # Adjust in case the base library changes. | ||
| assert aiohttp_session.__version__ == "2.11.0" # nosec | ||
| # -------------------------------------------------------- | ||
| 
     | 
||
| if max_age is not None: | ||
| params["max_age"] = max_age | ||
| t = time.gmtime(time.time() + max_age) | ||
| params["expires"] = time.strftime("%a, %d-%b-%Y %T GMT", t) | ||
| 
     | 
||
| if not cookie_data: | ||
| response.del_cookie( | ||
| self._cookie_name, | ||
| domain=params.get("domain"), | ||
| path=params.get("path", "/"), | ||
| ) | ||
| else: | ||
| response.set_cookie(self._cookie_name, cookie_data, **params) | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.