• 
      

    Consolidate our web login and credentials prompt auth logic.

    Review Request #14575 — Created Sept. 8, 2025 and submitted

    Information

    RBTools
    release-5.x

    Reviewers

    The get_authenticated_session() and BaseCommand.credentials_prompt()
    functions both contain the same code for prompting users for their
    username and password in the terminal. These need to be merged so we
    don't have to maintain two copies of the same code. The functions aren't
    direct replacements for one another though, they have different usages.
    So instead we pull out the credentials prompt logic into a
    credentials_prompt() function, which the above functions can call.

    Previously, only get_authenticated_session() contained the logic for
    kicking off web-based login. But we want to enable web-based login for
    all rbt commands, not just the ones that call get_authenticated_session().
    We now pull out the logic into an attempt_web_login() function that
    anything can call when they want to authenticate a client using
    web-based login.

    In the next change we'll make use of this function in a new auth handler
    that lets us try web-based login if enabled before falling back on Basic
    auth.

    • Ran unit tests.
    • Tested using all versions of the web login, open browser, and
      debug/logging options and their .reviewboardrc config values
      on rbt login, rbt post and rbt status.
    • Tested passing a username, a username and password, and an API
      token to commands.
    • Tested passing the same auth credentials above to commands while
      also passing --web-login (or setting in in .reviewboardrc), saw
      that the auth credentials were used instead.
    • Tested rbt post --diff-filename=- with piping a diff into STDIN
      while also passing --web-login. Was able to login using web
      auth before the rest of the command ran.
    Summary ID
    Consolidate our web login and credentials prompt auth logic.
    The `get_authenticated_session()` and `BaseCommand.credentials_prompt()` functions both contain the same code for prompting users for their username and password in the terminal. These need to be merged so we don't have to maintain two copies of the same code. The functions aren't direct replacements for one another though, they have different usages. So instead we pull out the credentials prompt logic into a `credentials_prompt()` function, which the above functions can call. Previously, only `get_authenticated_session()` contained the logic for kicking off web-based login. But we want to enable web-based login for all rbt commands, not just the ones that call `get_authenticated_session()`. We now pull out the logic into an `attempt_web_login()` function that anything can call when they want to authenticate a client using web-based login. In the next change we'll make use of this function in a new auth handler that lets us try web-based login if enabled before falling back on Basic auth.
    19fc9926fa084c087b41aba9109455aa08ac768f
    Description From Last Updated

    There's still a leading blank line here.

    chipx86chipx86

    This is missing docs for server_url and is_retry, and Returns.

    chipx86chipx86

    Let's make all these keyword-only, so we're more free to change these as needs change.

    chipx86chipx86

    This can be (Capabilities | None) = None.

    chipx86chipx86

    We should check if we're expecting web auth, and allow this to proceed if so.

    daviddavid

    Can you add type hints to this while you're at it?

    daviddavid

    These can use (str | None) = None

    daviddavid

    Please add a blank line before the return

    daviddavid

    Let's go with 5.4.

    chipx86chipx86

    We should pass server_url as a parameter, rather than using f-strings.

    chipx86chipx86
    chipx86
    1. 
        
    2. rbtools/commands/base/commands.py (Diff revision 1)
       
       
       
       
       
       
      Show all issues

      There's still a leading blank line here.

    3. rbtools/utils/users.py (Diff revision 1)
       
       
       
       
       
       
      Show all issues

      This is missing docs for server_url and is_retry, and Returns.

    4. rbtools/utils/web_login.py (Diff revision 1)
       
       
       
      Show all issues

      Let's make all these keyword-only, so we're more free to change these as needs change.

    5. rbtools/utils/web_login.py (Diff revision 1)
       
       
      Show all issues

      This can be (Capabilities | None) = None.

    6. 
        
    maubin
    david
    1. So glad to see this finally happen, this has always bugged me.

    2. rbtools/commands/base/commands.py (Diff revision 2)
       
       
       
       
       
      Show all issues

      We should check if we're expecting web auth, and allow this to proceed if so.

      1. If we're expecting web auth, the web auth handler will be called before this credentials prompt, so we would never reach this scenario.

    3. rbtools/utils/users.py (Diff revision 2)
       
       
      Show all issues

      Can you add type hints to this while you're at it?

      1. You already added type hints to this whole file on master :p which is why I left them out here. get_user in particular has a UserItemResource return type which doesn't exist on this branch yet.

    4. rbtools/utils/users.py (Diff revision 2)
       
       
       
      Show all issues

      These can use (str | None) = None

    5. rbtools/utils/web_login.py (Diff revision 2)
       
       
       
      Show all issues

      Please add a blank line before the return

    6. 
        
    maubin
    david
    1. Ship It!
    2. 
        
    maubin
    david
    1. Ship It!
    2. 
        
    chipx86
    1. 
        
    2. rbtools/utils/users.py (Diff revision 4)
       
       
      Show all issues

      Let's go with 5.4.

    3. rbtools/utils/users.py (Diff revision 4)
       
       
       
      Show all issues

      We should pass server_url as a parameter, rather than using f-strings.

    4. 
        
    maubin
    david
    1. Ship It!
    2. 
        
    chipx86
    1. Ship It!
    2. 
        
    maubin
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-5.x (1fb0487)