Skip to content
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

Propose PR solving issues #97 and #98 #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

PrieJos
Copy link
Contributor

@PrieJos PrieJos commented Aug 22, 2024

Proposed solutions to the following issues opened by myself:

Linting and test checks are all passed after modifications.

Please take a look and hope you can merge them upstream.

Thanks
Jose M. Prieto

Fix case sensitiveness in HTTPHeaderDict. See issue aliev#97 for
more details.
Fix compliant issue with implicit grant type reported in the
issue aliev#98.
Copy link
Owner

@aliev aliev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few minor comments, but overall, it looks great!

@@ -33,8 +34,24 @@ class HTTPHeaderDict(UserDict):
d['hElLo'] == 'world' # >>> True
"""

def __init__(self, dict=None, /, **kwargs):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Positional-only parameters are supported starting from Python 3.8. I'm not sure whether we still need to support Python 3.7, but for now, I would stick to maintaining that compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was mainly copied from original code from UserDict. That's why that signature

@@ -9,6 +9,7 @@
"""

from collections import UserDict
from typing import Any


class HTTPHeaderDict(UserDict):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To "solidify" these changes, I would create a test file for collections.py (e.g., test_collections.py) with tests like these:

def test_http_header_dict_case_insensitive_get():
    headers = HTTPHeaderDict(Authorization="Bearer token")
    assert headers.get("authorization") == "Bearer token"
    assert headers.get("Authorization") == "Bearer token"
    assert headers.get("AUTHORIZATION") == "Bearer token"
    assert headers.get("nonexistent", "default") == "default"


def test_http_header_dict_case_insensitive_delitem():
    headers = HTTPHeaderDict(Authorization="Bearer token")
    del headers["authorization"]
    assert headers.get("Authorization") is None


def test_http_header_dict_case_insensitive_init():
    headers = HTTPHeaderDict(**{"Authorization": "Bearer token", "Content-Type": "application/json"})
    assert headers.get("authorization") == "Bearer token"
    assert headers.get("content-type") == "application/json"

access_token=token.access_token,
refresh_token=token.refresh_token,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got a bit confused about removing the refresh_token from the response. How will the client get a refresh token if it needs to update the access_token? Auth0 uses the offline_access scope for this: https://auth0.com/docs/secure/tokens/refresh-tokens/get-refresh-tokens

This document says that the response MAY contain a refresh_token: https://www.oauth.com/oauth2-servers/making-authenticated-requests/refreshing-an-access-token/

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another solution could be a feature flag. If it's enabled, the refresh token won't be returned in the response. This way, backward compatibility won't be broken, while still adhering to the behavior outlined in the RFC6749 standard.

Copy link
Contributor Author

@PrieJos PrieJos Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I see your point @aliev. However, this is something very specific of the Implicit Grant. Indeed, the RFC 6749 clearly mentions that this flow was not conceived for refresh tokens:

The implicit grant type is used to obtain access tokens (it does not
support the issuance of refresh tokens) and is optimized for public
clients known to operate a particular redirection URI. These clients
are typically implemented in a browser using a scripting language
such as JavaScript.

(source: RFC 6749, section "4.2 Implicit Grant")

And also here:

The authorization server MUST NOT issue a refresh token.
(source: 4.2.2. Access Token Response)

Regarding this Auth0 link you paste before, the blog is very generic explanation about refresh token, so I guess they didn't really mean it in a concrete context like Implicit Grant. I think this may be why.

In any case, your proposal here:

Another solution could be a feature flag. If it's enabled, the refresh token won't be returned in the response. This way, backward compatibility won't be broken, while still adhering to the behavior outlined in the RFC6749 standard.

looks quite fine to me so that it leaves the decision to the implementer to be fully compliant or not!

Thanks again @aliev !!!

Cheers
Jose M. Prieto

PS: by the way, sorry for the long time I took in replying you, but your know, I was off in my summer break :P

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PrieJos! Could you create another PR to fix the issue you mentioned in #97 while I research the refresh token? I would really appreciate your contribution and would be happy to see you on the list of contributors! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @aliev

Here it goes the PR for issue #97: #103

Thanks
Jose M. Prieto

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PrieJos !

Shall we try to deliver this MR as well?

As I mentioned, the safest way would be to implement a feature flag disabled by default.

You could add it, for example, in the Settings: https://github.com/aliev/aioauth/blob/master/aioauth/config.py#L15

We should also remove the changes related to HTTPHeaderDict from this PR, as they are already in the master branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @aliev

Sorry for the long time to reply. I totally oversee the notification. Sorry again.

Yes, that would be great. I will take a look and come out with a suggestion so that you can review it.

Cheers,
Jose M. Prieto

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PrieJos

No worries, thank you for your contribution again!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @aliev,

I'll propose to continue the discussion on the original issue #98 instead of this PR since it became now obsolete after I pushed the new PR #108 for the final proposed solution.

Cheers
Jose M. Prieto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants