[WIP]Add OAuth2 provider support
Review Request #7285 — Created May 2, 2015 and discarded
This is about making Review Board work as an OAuth2 provider, so that other services can link up with Review Board and request permissions to perform operations.
About the code
- the
add_valid_policy_ids
inreviewboard/settings.py
is a recursive function to walking the WebAPIResource tree for adding scopes to OAUTH2_PROVIDER.SCOPES which will be used for validation inAccessToken.allow_scopes
(inoauth2_provider/models.py
)
- modify
WebAPIResource.call_method_view
(inreviewboard/webapi/base.py
) to not just check the policies around API Tokens, but also any OAuth2 tokens.
How to use
- Firstly install the toolkit:
pip install django-oauth-toolkit
- Now we can use following shell to get the access token.
curl -X POST -d "grant_type=password&username=<user_name>&password=<password>&scope=read" -u"<client_id>:<client_secret>" http://localhost:8000/o/token/
- We can use following code to access
UserResource
[We useWebAPIResource.policy_id
for the scope name of that resource]. Thus we succuessfully apply the verify mechanism to our code.
curl -H "Authorization: Bearer <your_access_token_with_user_scope>" http://localhost:8000/api/users/<username>/
Description | From | Last Updated |
---|---|---|
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
Col: 18 E126 continuation line over-indented for hanging indent |
reviewbot | |
Col: 80 E501 line too long (95 > 79 characters) |
reviewbot | |
'PIPELINE_JS' imported but unused |
reviewbot | |
'PIPELINE_CSS' imported but unused |
reviewbot | |
Col: 80 E501 line too long (84 > 79 characters) |
reviewbot | |
Col: 2 W292 no newline at end of file |
reviewbot | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
Col: 18 E126 continuation line over-indented for hanging indent |
reviewbot | |
'PIPELINE_JS' imported but unused |
reviewbot | |
'PIPELINE_CSS' imported but unused |
reviewbot | |
Col: 80 E501 line too long (84 > 79 characters) |
reviewbot | |
Col: 20 E225 missing whitespace around operator |
reviewbot | |
Col: 25 E231 missing whitespace after ',' |
reviewbot | |
Col: 9 E265 block comment should start with '# ' |
reviewbot | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
Col: 18 E126 continuation line over-indented for hanging indent |
reviewbot | |
'PIPELINE_JS' imported but unused |
reviewbot | |
'PIPELINE_CSS' imported but unused |
reviewbot | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 8 E111 indentation is not a multiple of four |
reviewbot | |
Col: 1 E402 module level import not at top of file |
reviewbot | |
Col: 37 W292 no newline at end of file |
reviewbot | |
Col: 5 E265 block comment should start with '# ' |
reviewbot | |
Col: 20 E225 missing whitespace around operator |
reviewbot | |
Col: 25 E231 missing whitespace after ',' |
reviewbot | |
Col: 9 E265 block comment should start with '# ' |
reviewbot | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
'PIPELINE_CSS' imported but unused |
reviewbot | |
'PIPELINE_JS' imported but unused |
reviewbot | |
Col: 1 E402 module level import not at top of file |
reviewbot | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
'PIPELINE_JS' imported but unused |
reviewbot | |
'PIPELINE_CSS' imported but unused |
reviewbot | |
Needs a docstring. |
brennie | |
No blank line here. |
brennie | |
You can use %-formatting to build this string more efficiently. |
brennie | |
These should go with the django/djblets imports. |
brennie | |
This doesn't need a leading underscore. |
brennie | |
Needs a docstring. |
brennie | |
You can use .split(' ', 1)[0] to get only the first element out. |
brennie | |
Needs a docstring. |
brennie | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
'PIPELINE_JS' imported but unused |
reviewbot | |
'PIPELINE_CSS' imported but unused |
reviewbot | |
Col: 1 E402 module level import not at top of file |
reviewbot | |
Docstrings should be of the format: """Single line summary. Multi-line description. """ |
brennie | |
This should end with a period and the trailing """" should be on the previous line. |
brennie | |
Blank line between these. |
brennie | |
Needs periods. |
brennie | |
This should say something like "The policy_id field is determines the default scope that is used for the resources. Child … |
brennie | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
'PIPELINE_JS' imported but unused |
reviewbot | |
'PIPELINE_CSS' imported but unused |
reviewbot | |
Col: 1 E402 module level import not at top of file |
reviewbot | |
Where this part should be? |
LE lehoangm |
- Change Summary:
-
Combine the verify part of OAuth code into ReviewBoard
- Description:
-
~ Just codes following the tutorial
~ Firstly I follow the tutorial:
- - The link of the tutorial:
https://django-oauth-toolkit.readthedocs.org/en/latest/tutorial/tutorial.html ~ 1.Now we can use following shell to get the access token.
~ 1.
+ Now we can use following shell to get the access token. curl -X POST -d "grant_type=password&username=<user_name>&password=<password>&scope=read" -u"<client_id>:<client_secret>" http://localhost:8000/o/token/ ~ - Then we can use following code to access the view needed OAuth scope
curl -H "Authorization: Bearer <your_access_token>" http://localhost:8000/users/
~ Then we can use following code to access the view needed OAuth scope
+ curl -H "Authorization: Bearer <your_access_token>" http://localhost:8000/getusers/ + + 2.
+ We can use following code to access UserResource
[We useWebAPIResource.policy_id
for the scope name of that resource]. Thus we succuessfully apply the verify mechanism to our code.+ curl -H "Authorization: Bearer <your_access_token_with_user_scope>" http://localhost:8000/api/users/test - Then we can use following code to access the view needed OAuth scope
- Commit:
-
5f470814f6e0906fca45592f70d41d4c68d2d370be1027c671f4d9219f7d948b1b88c8fc4cb99ce2
-
Tool: Pyflakes Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py
-
-
-
-
-
-
-
-
-
- Change Summary:
-
Add scopes to OAUTH2_PROVIDER.SCOPES by walking the WebAPIResource tree and remove useless code about tutorials
- Description:
-
~ Firstly I follow the tutorial:
~ This is about making Review Board work as an OAuth2 provider, so that other services can link up with Review Board and request permissions to perform operations.
- https://django-oauth-toolkit.readthedocs.org/en/latest/tutorial/tutorial.html ~ 1.
~ About the code
- Now we can use following shell to get the access token. - curl -X POST -d "grant_type=password&username=<user_name>&password=<password>&scope=read" -u"<client_id>:<client_secret>" http://localhost:8000/o/token/ ~ Then we can use following code to access the view needed OAuth scope
~ - the
add_valid_policy_ids
inreviewboard/settings.py
is a recursive function to walking the WebAPIResource tree for adding scopes to OAUTH2_PROVIDER.SCOPES which will be used for validation inAccessToken.allow_scopes
(inoauth2_provider/models.py
)
- curl -H "Authorization: Bearer <your_access_token>" http://localhost:8000/getusers/ ~ 2.
~ We can use following code to access UserResource
[We useWebAPIResource.policy_id
for the scope name of that resource]. Thus we succuessfully apply the verify mechanism to our code.~ curl -H "Authorization: Bearer <your_access_token_with_user_scope>" http://localhost:8000/api/users/test ~ ~ ~ - modify
WebAPIResource.call_method_view
(inreviewboard/webapi/base.py
) to not just check the policies around API Tokens, but also any OAuth2 tokens.
+ + + + How to use
+ + - Firstly install the toolkit:
+ + pip install django-oauth-toolkit
+ + + - Now we can use following shell to get the access token.
+ + curl -X POST -d "grant_type=password&username=<user_name>&password=<password>&scope=read" -u"<client_id>:<client_secret>" http://localhost:8000/o/token/
+ + + - We can use following code to access
UserResource
[We useWebAPIResource.policy_id
for the scope name of that resource]. Thus we succuessfully apply the verify mechanism to our code.
+ + curl -H "Authorization: Bearer <your_access_token_with_user_scope>" http://localhost:8000/api/users/<username>/
+ - the
- Commit:
-
be1027c671f4d9219f7d948b1b88c8fc4cb99ce283eba08234ca6408e9307a14cf09c46946447478
-
Tool: Pyflakes Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py
-
-
-
-
-
-
-
-
-
-
-
-
-
- Change Summary:
-
correct format errors
- Commit:
-
83eba08234ca6408e9307a14cf09c46946447478be9baa727dcb358dddf6da6063536fcafd4a5a6a
-
Tool: Pyflakes Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py
-
-
-
-
-
-
Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py Tool: Pyflakes Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py
-
-
-
-
- Change Summary:
-
add some docstring
- Commit:
-
4d639473d1e8d3b917ed6ba1bebbba562d07b0defaf253e7548e786b10f4aa997e2ad33e97f1dba9
-
Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py Tool: Pyflakes Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py
-
-
-
-
-
- Change Summary:
-
correct docstrings
- Commit:
-
faf253e7548e786b10f4aa997e2ad33e97f1dba97088d64ef2a53b7869372f57c958ca1e72de9318
-
Tool: Pyflakes Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/base.py reviewboard/settings.py reviewboard/urls.py
-
-
-
-
-
-
Thanks for taking this on, Chenxi! I'm sorry we've been so busy lately. I can tell you our goal is for this to be one of the key features of Review Board 2.6 :)
What work is left to get this out of WIP?
What else would remain for full OAuth2 support? For instance, other OAuth2 providers have a page that a client can pop up that lets the user confirm the client's access, and will then provide the client with a token. Usually that has the provider's logo/name, and the client's logo/name, and a list of things to request for access. Do we have anything for that? I don't know how much the module we're using automatically gives us.