-
Couldn't load subscription status.
- Fork 79
Oauth2 addition #1562
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
Oauth2 addition #1562
Conversation
|
Do not merge this changes until I can test this locally with a working system. |
|
@squirrelo could you pull from artifact? Thanks! |
|
pulled from artifact. Also added daily request limiting. |
|
The auth check is now a decorator, so this should be in a final state and ready for review. |
|
Hmm. Looks like there are some test files that can't be found ... |
|
I can't reproduce the test error on my system. Anyone have ideas? |
|
@squirrelo will investigate shortly - I'm planning to pull this down, and test locally, so I can also update the plugins accordingly |
|
Changes made, save ones we need to discuss as a group. |
qiita_db/handlers/oauth2.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?! Define the function here - you can then call the function in the decorator, as you are calling other methods/attributes of the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As stated previously, the decorator function is for anything extending tornado's RequestHandler, not specifically the oauth handler, and the changes just pushed reflect that. Calling the function in the decorator breaks this functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting really confused here. As you stated here, the authenticate_oauth is written so it works with any RequestHandler. On the other hand, you created the base class OauthBaseHandler that all the handlers that require oauth2 need to subclass. The question then is, is the OauthBaseHandler class needed or the authenticate_oauth really need to be as general for any of the Handlers type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OauthBaseHandler is for anything that needs to actually set and manipulate the authorization keys in the system, or authenticate user/client information, so not every oauth2 using page needs to subclass it. I did it for convenience, as there are things like 404 and error handling that are better used in base classes, but it's not strictly needed. Leaving the decorator open like this allows extensibility in the future with no code change, as all you need to do is import the authenticate_oauth decorator and extend RequestHandler again, exactly the same as the tornado library already works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any specific necessity of calling oauth_error as self.oauth_error? If not, remove this line and and just call the function _oauth_error as _oauth_error(self, params...). This is just making maintaining the code harder.
|
Can we close this one? I think it has been superseded by #1584 .. |
|
It would be much easier to review in two parts, as #1584 becomes monolithic with this PR merged in as well. |
|
OK, reviewing now. |
qiita_db/handlers/oauth2.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have a doc string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the inner wrapper of the decorator, so no. The docstring of the containingauthenticate_oauth function is what's going to be seen.
|
Comments addressed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Returns is a misnomer here, since it doesn't actually return anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I was saying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mortonjt in a previous discussion over email we agreed on documenting the RESTapi using the numpy returns.
We are happy to change to a different standard to document the RESTapi in the same code, but please provide alternatives - it is better to document like this than leave undocumented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the examples section would be easier, especially since these all respond differently depending on errors, warnings, etc and that could be documented better.
This pull request adds Oauth2-style authentication to the API. Every plugin now requires a client_id and client_secret to ping the API with to get an access token. This access token allows connection for one hour, and then the token will need to be re-created and the new one used. Users can also get access by giving a client ID and their username and password. This allows us to have a secure login system for the API that can also be secured on a per-user basis as well as a per-client (plugin) basis.
Two of the four access types have been implemented: Client Credentials Grant for the plugins and Resource Owner Password Credentials Grant for qiita-pet.