[9.0] Add oauth_provider module - #611
Conversation
6840486 to
f82b89e
Compare
|
Travis errors unrelated (from database_cleanup and auth_signup_verify_email modules). |
5270939 to
4e6857e
Compare
|
Last little thing done (and rebased on 9.0). |
4e6857e to
7dfe322
Compare
7dfe322 to
a5dc3af
Compare
lasley
left a comment
There was a problem hiding this comment.
Awesome thanks @sylvain-garancher - comments inline. Also my bad on leaving the WIP tag for so long, missed the comment.
| '/oauth2/authorize', type='http', auth='user', methods=['POST']) | ||
| def authorize_post(self, *args, **kwargs): | ||
| """ | ||
| Redirect to the requested URI during the authorization |
There was a problem hiding this comment.
Not a blocker or anything, just FYI - Docstrings should start on the same line that the quote is started on. The first line (in a multi) should be a complete summary, followed by a blank line, followed by more description if necessary. Check out PEP-257 for more
There was a problem hiding this comment.
Didn't know that, thanks.
I'll have to change my comments on many other PRs :D
There was a problem hiding this comment.
Hah it's one of those things that you can't unsee once you know it, right?!
| http.request.httprequest.values.items()) | ||
| headers = http.request.httprequest.headers | ||
|
|
||
| valid, oauthlib_request = oauth2_server.verify_request( |
There was a problem hiding this comment.
This token & argument retrieval followed verification block seems to be repeated a lot. It would be nice if it was just a helper method instead.
There was a problem hiding this comment.
You're right, I'll provide a helper method (which will be useful for modules depending on this one too).
| Authenticate the client | ||
| """ | ||
| raise NotImplementedError | ||
| # return False |
There was a problem hiding this comment.
Please remove this commented code
There was a problem hiding this comment.
I leaved this line here to remind the return value's type, but I may add this in the docstring.
There was a problem hiding this comment.
Docstring would be the preferred please 😄
| """ | ||
| Authenticate the client | ||
| """ | ||
| raise NotImplementedError |
There was a problem hiding this comment.
No client auth implementation?
There was a problem hiding this comment.
This file is an implementation of the interface provided by the oauthlib module.
As the user is already logged on Odoo, we have the user in the request.env, so I didn't need to implement this method (unless I miss something).
There was a problem hiding this comment.
Nope nope, was definitely me missing something. Can we add a docstring note that this is an interface then?
| request.client = http.request.env['oauth.provider.client'].search([ | ||
| ('identifier', '=', client_id), | ||
| ]) | ||
| request.odoo_user = http.request.env['oauth.provider.client'].env.user |
There was a problem hiding this comment.
Why the env and user from oauth.provider.client? It's the same env and user isn't it, or is there some fancy context switching that I am missing?
There was a problem hiding this comment.
I think this is a bad copy/paste from the previous line, I'll fix that :)
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <openerp> | ||
| <data> | ||
| ############################################################################## |
There was a problem hiding this comment.
Wait... how is this not breaking XML? Please use the shorter header though, and put just under the xml version. This is how I do it https://github.com/OCA/vertical-medical/blob/9.0/medical/views/medical_menu.xml#L3 - although we don't have specific guidelines in OCA on the XML part AFAIK
There was a problem hiding this comment.
This is part of our own templates since at least v5, I think this is time to update our templates.
I'll change that.
| @@ -0,0 +1,53 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <openerp> | |||
There was a problem hiding this comment.
<odoo> and can remove data tag
There was a problem hiding this comment.
Oops, I kept the old templates for my XML files :)
| @@ -0,0 +1,60 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <openerp> | |||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <openerp> | ||
| <data> | ||
| ############################################################################## |
There was a problem hiding this comment.
Same note regarding use of smaller header
| self.assertEqual(client.grant_type, 'authorization_code') | ||
| self.assertEqual(client.response_type, 'code') | ||
|
|
||
| # Web Application |
There was a problem hiding this comment.
IMO the scope of all these tests is too large. It's best to make smaller test methods in order to provide a better view of things when stuff is broken vs. execution stopping on the first broken test.
There was a problem hiding this comment.
You advise to split in one test method per possible value ?
I left all in a single method, because every test in this method are really close, but I don't know all best practices about tests.
There was a problem hiding this comment.
Yeah the smaller the test the better. I go to great lengths to follow a 1:1 method:assertion ratio, but sometimes it's not possible given context and setup required.
Consider an example using these tests. If the response_type for the web application is wrong, we won't know if it's right for Mobile, Legacy, and Backend because the test will stop execution at the first failed assertion.
It's incredibly valuable to have the whole picture when debugging failing tests because it can help point us closer to the actual error, or specific edge case that is being debugged (maybe only X of the Y are failing).
There was a problem hiding this comment.
Ok, I understand. I'll split the tests when it is possible ;)
f3b8cb7 to
21677c1
Compare
|
@lasley I updated the PR with all of your comments. I also created a common class for both controllers tests (initialization and many tests are the same for all controllers). |
21677c1 to
9bb61bf
Compare
|
Rebased on 9.0, but runbot seems broken. |
lasley
left a comment
There was a problem hiding this comment.
@sylvain-garancher LGTM OCA/runbot-addons#111 for Runbot issue, which is definitely not related to anything you did
moylop260
left a comment
There was a problem hiding this comment.
LGTM
I'll review the runbot issue
|
I'll finally have to implement the password credentials grant (token request by providing username and password), and add it in this PR. |
|
A short reminder for myself : Check if everything works well with multiple databases (unauthenticated routes may not work if no database has been selected). |
3680b62 to
e2a3631
Compare
|
Tests split is finished, I think this is good now, so I removd the WIP tag in title. |
0af84ff to
0c95d22
Compare
|
After a rebase on 9.0, Travis is failing on many other modules, but not on this module's tests. |
|
After many tests, my customer has no new issue now, using the "legacy application" profile. |
|
I have an issue with the default values for UUID fields ( When installing the module, all existing users get the same UUID as identifier... which is not what we want. How could we generate a new random UUID for each user ? I initially though about a |
0c95d22 to
5a177fe
Compare
|
We circumvented this in medical by moving the default generation into an overrided create method instead. Looks like that would still work here? Basiccally: Downfall of this is from a UI perspective, because the default won't exist until save. We considered it not a problem in our context, and I don't think it would be here either - the val is read-only for humans anyways. |
1efa5a2 to
c00a067
Compare
|
I added the I also added the missing Do you still see a need for overriding the |
|
@> Do you still see a need for overriding the create method ? Nope, I'd say you covered the bases. We ended up having to implement the create I think due to layers and layers of delegate inheritance at play & some connectors that bulk add data in ways a user normally wouldn't. Looks like lint is 🔴 though. The other two failures are known, one of which is being resolved in #719 & the other should clear itself per Pedro's email earlier. |
c00a067 to
2e3bada
Compare
2e3bada to
d0b2501
Compare
|
Lint fixed, rebased on 9.0 to benefit from the tests fixes of the database_cleanup module. |
d0b2501 to
f59ef9a
Compare
|
Rebased on 9.0 to resolve the requirements.txt conflict. |
lasley
left a comment
There was a problem hiding this comment.
We've been in prod for a few weeks now too. Excellent work, @sylvain-garancher
f59ef9a to
0aa4b7e
Compare
|
Rebased on 9.0 to fix the |
|
Thanks for another badass module @sylvain-garancher |
Syncing from upstream OCA/server-tools (12.0)
A new module that allows to use Odoo as OAuth provider.
The OAuth protocol is used to delegate authentication, and authorization to access some resources.
This module really need security reviews/tests, as I'm not fully comfortable with the OAuh protocol.
The RFC defines four profiles: Implicit grant, Authorization code grant, Password credentials grand and User credentials grant.
Only Implicit grant and Authorization code grant are implemented yet, and I don't plan to implement the others for now. The work should not be very hard, as most parts are common, but I don't actually need these profiles, and don't have time to do it for the moment.
Note: I created the PR to allow you to begin testing the module.
@pedrobaeza said that this repo will be split into several smaller repos, this PR will need to be recreated on one of the new repos when they are created.