Git Merge Request #414: Update docs and wiki-copy example for OAuth2 support (merged)

Merging...

Merged

Something went wrong. Please, merge manually

Checking if merge is possible...

Something went wrong. Please, merge manually

Carlos Cruz wants to merge 1 commit from /u/ccruz/allura/ to master, 2024-05-17

  • Updated docs with code examples on how to use OAuth2 authorization and token features
  • Updated the wiki-copy.py script to support OAuth2 which also serves as an example of how to create a script using OAuth2 security and how to automatically refresh access tokens
  • Fixed issues with requesting new access tokens using a refresh token
Commit Date  
[eef368] (cc/9358) by Carlos Cruz Carlos Cruz

[#7272] Update docs and wiki-copy script for OAuth2

2024-05-13 21:46:37 Tree

Discussion

  • Dave Brondsema

    Dave Brondsema - 2024-05-16
      File "/var/local/env-allura/lib/python3.11/site-packages/oauthlib/oauth2/rfc6749/endpoints/authorization.py", line 114, in validate_authorization_request
        return response_type_handler.validate_authorization_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/var/local/env-allura/lib/python3.11/site-packages/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py", line 367, in validate_authorization_request
        self._handle_redirects(request)
      File "/var/local/env-allura/lib/python3.11/site-packages/oauthlib/oauth2/rfc6749/grant_types/base.py", line 249, in _handle_redirects
        raise errors.MissingRedirectURIError(request=request)
    oauthlib.oauth2.rfc6749.errors.MissingRedirectURIError: (invalid_request) Missing redirect URI. <oauthlib.Request SANITIZED>
    
    • then using one that did have a redirect, after I approved it I got redirected. I see the code in the URL, but that's probably not the best. On oauth1 there was a mode that showed the code on the page instead of redirecting. Can we do something like that? Not sure how to know when to redirect or not, especially in relationship to the above error? Maybe if the current request doesn't ask for a redirect?
    • test_run_precommit has these errors:
    E   scripts/wiki-copy.py:131:        token_expires = datetime.now() + timedelta(seconds=token.get('expires_in'))
    E   scripts/wiki-copy.py:159:        token_expires = datetime.now() + timedelta(seconds=response.get('expires_in'))
    E   scripts/wiki-copy.py:174:        date_diff = datetime.fromtimestamp(int(expires_in)) - datetime.utcnow()
    
     
  • Carlos Cruz - 2024-05-17
    • Removed the revoke_token method since we already have our internal mechanism to revoke tokens
    • save_bearer_token uses user_id because it's a public endpoint that doesn't require authentication so we attempt to fetch the user id depending on the grant_type instead than from the current context
    • Added the correct OAuth2 settings for the raml file
    • Updated /auth/oauth2/ to /auth/oauth in wiki-copy.py
    • For the redirect issues, we agreed that upon registering a new client the user must add at least one redirect URI to simplify workflow validations
    • Fixed ruff errors
    • While looking at the redirect issues I found that we also needed to implement the confirm_redirect_url in the OAuth2 validator to make sure that the same redirect uri the authorization code was created with, is also used when requesting an access token
     
  • Dave Brondsema

    Dave Brondsema - 2024-05-17

    There already is a confirm_redirect_uri and it has the same code :D

    in the api docs, you included client_credentials which does match what we have in validate_grant_type, but I'm wondering if we need it at all. Maybe in next merge request can decide if that is what we use for personal bearer tokens? Or if we don't need it, we should remove it entirely.

     
  • Dave Brondsema

    Dave Brondsema - 2024-05-17
    • Status: open --> merged
     

Log in to post a comment.