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

Openid Connect Core support #545

Closed
wants to merge 48 commits into from

Conversation

wiliamsouza
Copy link
Member

@wiliamsouza wiliamsouza commented Jan 18, 2018

This PR add OpenID Connect Core http://openid.net/specs/openid-connect-core-1_0.html support.

To run the tests do:

Django OAuth Toolkit cloned repository

git remote add git@github.com:wiliamsouza/django-oauth-toolkit.git wiliamsouza
git checkout -b openid-connect wiliamsouza/openid-connect
tox

Usage examples:

Authorization-code

http://openid.net/specs/openid-connect-core-1_0.html#CodeFlowAuth

token and id_token

http://127.0.0.1:8000/o/authorize?response_type=code&client_id=HCSTniKnHNj6qP6Dkms39q6IT4pahzfXws2uwTkS&redirect_uri=http://localhost/callback&scope=openid%20read&state=af0ifjsldkj&nonce=n-0S6_WzA2Mj

Only token

http://127.0.0.1:8000/o/authorize?response_type=code&client_id=HCSTniKnHNj6qP6Dkms39q6IT4pahzfXws2uwTkS&redirect_uri=http://localhost/callback&scope=read&state=af0ifjsldkj&nonce=n-0S6_WzA2Mj
curl -X POST \
    -H "Cache-Control: no-cache" \
    -H "Content-Type: application/x-www-form-urlencoded" \
    "http://127.0.0.1:8000/o/token/" \
    -d "client_id=HCSTniKnHNj6qP6Dkms39q6IT4pahzfXws2uwTkS" \
    -d "client_secret=Ay1rH78PChsOG4mshfdp2oJnomdpu5Vgtdz6jCmDkEM8mKHzcaKo5GEYNGK42KTN8XqEWbbpn1vdHJKYcBgawONx4S1xXY7GtEP9mvsMw593DeXH0aRpWlgySuxeDfe2" \
    -d "code=89BRsh4kQqrwlNMLj4coVZbrpDm0Mh" \
    -d "redirect_uri=http://localhost/callback" \
    -d "grant_type=authorization_code"

implicit

http://openid.net/specs/openid-connect-core-1_0.html#ImplicitFlowAuth

token

http://127.0.0.1:8000/o/authorize?response_type=token&client_id=Ktn0Sh4hO2gA8PKC2aqsauY4ZCxNyIdF1wNfFfJ3&redirect_uri=http://localhost/callback&scope=openid%20read&state=af0ifjsldkj&nonce=n-0S6_WzA2Mj

id_token

http://127.0.0.1:8000/o/authorize?response_type=id_token&client_id=Ktn0Sh4hO2gA8PKC2aqsauY4ZCxNyIdF1wNfFfJ3&redirect_uri=http://localhost/callback&scope=openid%20read&state=af0ifjsldkj&nonce=n-0S6_WzA2Mj

token and id_token

http://127.0.0.1:8000/o/authorize?response_type=id_token%20token&client_id=Ktn0Sh4hO2gA8PKC2aqsauY4ZCxNyIdF1wNfFfJ3&redirect_uri=http://localhost/callback&scope=openid%20read&state=af0ifjsldkj&nonce=n-0S6_WzA2Mj

openid-hybrid

http://openid.net/specs/openid-connect-core-1_0.html#HybridFlowAuth

code, id_token and token

http://127.0.0.1:8000/o/authorize?response_type=code%20id_token%20token&client_id=fZjUvm0YABo6mX1UTjo9VVYay9zj1HpaCZaoa4Fj&redirect_uri=http://localhost/callback&scope=openid%20read&state=af0ifjsldkj&nonce=n-0S6_WzA2Mj

code and id_token

http://127.0.0.1:8000/o/authorize?response_type=code%20id_token&client_id=fZjUvm0YABo6mX1UTjo9VVYay9zj1HpaCZaoa4Fj&redirect_uri=http://localhost/callback&scope=openid%20read&state=af0ifjsldkj&nonce=n-0S6_WzA2Mj

code and token

http://127.0.0.1:8000/o/authorize?response_type=code%20token&client_id=fZjUvm0YABo6mX1UTjo9VVYay9zj1HpaCZaoa4Fj&redirect_uri=http://localhost/callback&scope=openid%20read&state=af0ifjsldkj&nonce=n-0S6_WzA2Mj

code

http://127.0.0.1:8000/o/authorize?response_type=code&client_id=fZjUvm0YABo6mX1UTjo9VVYay9zj1HpaCZaoa4Fj&redirect_uri=http://localhost/callback&scope=openid%20read&state=af0ifjsldkj&nonce=n-0S6_WzA2Mj
curl -X POST \
    -H "Cache-Control: no-cache" \
    -H "Content-Type: application/x-www-form-urlencoded" \
    "http://127.0.0.1:8000/o/token/" \
    -d "client_id=fZjUvm0YABo6mX1UTjo9VVYay9zj1HpaCZaoa4Fj" \
    -d "client_secret=eiBw6IIQ4zzWFP9gSszEHZwexjCDhJjMtRxoOYQexCJMjQ6gdyN2ME9aUzbGkVopx3NSZRPUb4SV9yKpbVwwW9NKdEpkoyGmcTni7G4KTPqtJrsI9HPubFnDDzsvAf89" \
    -d "code=VQGv7tzYGO13jrRnv6oYT7jHbDSGJZ" \
    -d "redirect_uri=http://localhost/callback" \
    -d "grant_type=authorization_code"

TODO:

@coveralls
Copy link

coveralls commented Jan 18, 2018

Coverage Status

Coverage decreased (-4.7%) to 88.696% when pulling b2847e2 on wiliamsouza:openid-connect into 231efff on evonove:master.

@wiliamsouza wiliamsouza mentioned this pull request Jan 18, 2018
@wiliamsouza
Copy link
Member Author

The CI will be broke until OAuthLib version containing this PR oauthlib/oauthlib#488

@jleclanche
Copy link
Member

Hi @wiliamsouza

Thanks, this is a high quality PR. I'm not merging it until the upstream work is fully released, but once it is, feel free to ping here again and I'll do a full review pass.

@wiliamsouza
Copy link
Member Author

OAuthLib upcoming release 3.0.0 oauthlib/oauthlib#512

@rhenter
Copy link
Contributor

rhenter commented Mar 21, 2018

Great PR. It will be very good when It wore merged

@afabiani
Copy link

Hi all,
how far we are on merging this?

@JonathanHuot
Copy link
Contributor

@jleclanche, oauthlib's PR oauthlib/oauthlib#488 has been merged into oauthlib's master branch. Would be great to validate the changes here before releasing the oauthlib@3.0.0

@wiliamsouza
Copy link
Member Author

@afabiani As soon as oauthlib@3.0.0 get released

@jleclanche
Copy link
Member

@JonathanHuot Winter is pretty busy here, I'm not sure I'll soon be in a situation where i can do an updated review. And either way, I wouldn't want to land this without testing it (and I'm not in a position to test it).

So if people want to get this PR moving ahead of oauthlib 3.0 release, bring it into your installations and try it out, report back with any issues.

@wiliamsouza
Copy link
Member Author

@jleclanche @JonathanHuot I can manage this

@afabiani
Copy link

afabiani commented Oct 5, 2018

@wiliamsouza currently I had to fork this one [1] since it required few more changes in order to fully work with OIDC 1.0 (tested mainly using Keycloak). Will look forward to the new release anyway. Thanks.

[1] - https://github.com/GeoNode/geonode-oauth-toolkit

@jejenone
Copy link

jejenone commented Dec 3, 2018

I would love to see OIDC support in DOT. Looking forward to seeing this merged.

@bpereto
Copy link

bpereto commented Jan 9, 2019

@wiliamsouza oauthlib@3.0.0 is released 🎉

@tribals
Copy link

tribals commented Jan 11, 2019

@wiliamsouza

I created dummy Django app with this library integrated, seems like the patch is currently doesn't work.

Here is the app: https://dummy-idp-dot.herokuapp.com. I created an OAuth app, you can view it's credentials here: https://dummy-idp-dot.herokuapp.com/oauth/applications/1. I tested it with OpenID Connect debugger: https://oidcdebugger.com. Currently there is an unsupported_response_type error. Here is the request that Debugger was generated:

https://dummy-idp-dot.herokuapp.com/oauth/authorize?client_id=P25mgGSjKjx77Dw4zaiUhhJMWqYgtIVQiogSpATz&redirect_uri=https%3A%2F%2Foidcdebugger.com%2Fdebug&scope=openid%20read&response_type=token%20id_token&response_mode=form_post&nonce=lokuqbmajz

@wiliamsouza
Copy link
Member Author

Working on it

@coveralls
Copy link

coveralls commented Jan 16, 2019

Pull Request Test Coverage Report for Build 1345

  • 193 of 222 (86.94%) changed or added relevant lines in 11 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-1.05%) to 93.721%

Changes Missing Coverage Covered Lines Changed/Added Lines %
oauth2_provider/settings.py 5 7 71.43%
oauth2_provider/views/oidc.py 25 28 89.29%
oauth2_provider/oauth2_validators.py 103 110 93.64%
oauth2_provider/models.py 31 48 64.58%
Files with Coverage Reduction New Missed Lines %
oauth2_provider/settings.py 1 76.56%
oauth2_provider/oauth2_validators.py 2 91.33%
Totals Coverage Status
Change from base Build 1341: -1.05%
Covered Lines: 1418
Relevant Lines: 1513

💛 - Coveralls

@wiliamsouza
Copy link
Member Author

@afabiani Great! Can you explain the changes and how do you test it with Keycloak?

@wiliamsouza
Copy link
Member Author

@jejenone You can help it get done reviewing and testing this branch.

@wiliamsouza
Copy link
Member Author

@tribals Can you update the code and redo the test?

@tribals
Copy link

tribals commented Jan 17, 2019

@wiliamsouza Finally I'm testing in local environment. It seems to mostly work. I tried implicit flow with response_type parameter set to both token and id_token token. Server responds correctly. There are still some misunderstandings about how to hook into this library but they disappear as the more I work with library.

Copy link
Contributor

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

please re-base to master while updating.

Copy link
Contributor

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

it's better to pull updates from master and change models based on latest master, and then regenerate migrations based on the migrations in masters branch.

oauth2_provider/migrations/0008_application_algorithm.py Outdated Show resolved Hide resolved
oauth2_provider/migrations/0009_idtoken.py Outdated Show resolved Hide resolved
oauth2_provider/migrations/0010_accesstoken_id_token.py Outdated Show resolved Hide resolved
@wiliamsouza
Copy link
Member Author

@auvipy Your merge broke the build. Why did you do that before any discussion?

@wiliamsouza
Copy link
Member Author

@tribals @jleclanche @bpereto @auvipy @fvlima @jpbonson @JC127 @esseti @kaeruko @JonathanHuot @jejenone @afabiani Ready to merge? Review, comment! I can add access to my fork to anyone that want to help. Just ask.

@auvipy
Copy link
Contributor

auvipy commented Mar 2, 2020

tests are failing. you could add me to your branch

@n2ygk
Copy link
Member

n2ygk commented Mar 2, 2020

This is a big improvement and a lot of new code. I think we should hold off merging this until after the 1.3.0 release which I'm hoping to get out today or tomorrow. Given the significant new functionality, perhaps this becomes a 1.4.0 or 2.0 release. What are your thoughts on whether this is a major or minor release per semver?

And, of course, failing tests have to be resolved. They are mostly isort/flake8 issues because I undid the disabling of those tests in #798. They should be really easy to fix:

  • isort <filename> which will sort the includes properly
  • make sure to use inline double-quotes. (I just did this doing global replaces of ' with " and a few manual fixes)
  • comply with line-length limit
  • a few other items

@wiliamsouza
Copy link
Member Author

wiliamsouza commented Mar 2, 2020

tests are failing.

I will fix tests.

you could add me to your branch

Done! Welcome.

@wiliamsouza
Copy link
Member Author

wiliamsouza commented Mar 2, 2020

This is a big improvement and a lot of new code. I think we should hold off merging this until after the 1.3.0 release which I'm hoping to get out today or tomorrow.

Great!

Given the significant new functionality, perhaps this becomes a 1.4.0 or 2.0 release. What are your thoughts on whether this is a major or minor release per semver?

1.4.0 is ok.

@n2ygk n2ygk added this to the 1.4 milestone Mar 2, 2020
@@ -33,6 +34,7 @@ deps =
pytest-xdist
py27: mock
requests
jwcrypto

[testenv:py37-docs]
basepython = python
Copy link
Member

Choose a reason for hiding this comment

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

I believe you need to add jwcrypto to deps here as well to resolve tox -e py37-docs failure.

Copy link
Contributor

@fvlima fvlima Apr 27, 2020

Choose a reason for hiding this comment

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

And, of course, failing tests have to be resolved. They are mostly isort/flake8 issues because I undid the disabling of those tests in #798. They should be really easy to fix:

Those things were fixed here wiliamsouza#8. After merging this, only documentation and examples items (#545 (comment)) will remain to merge this PR

@wiliamsouza
Copy link
Member Author

Checklist

  • 1) Fix flake8 test
  • 2) Fix docs test
  • 3) Ensure coverage is higher
  • 4) Write docs about OpenID Connect
  • 5) Write a example application with OpenID connect flows

I think this the job that must be done.
Will take the 5 one.

@fvlima
Copy link
Contributor

fvlima commented Mar 3, 2020

I can fix the 1 and 2 items. And about item 3, is it really necessary to put the oauth2_provider/settings.py to be covered?

@wiliamsouza
Copy link
Member Author

wiliamsouza commented Mar 3, 2020

I can fix the 1 and 2 items. And about item 3, is it really necessary to put the oauth2_provider/settings.py to be covered?

It seems to have some logic.

@esseti
Copy link

esseti commented Mar 23, 2020

sorry to be late at the party, what/how can I help?

@wiliamsouza
Copy link
Member Author

sorry to be late at the party, what/how can I help?

Can you handle any item from the checklist?

@auvipy
Copy link
Contributor

auvipy commented Mar 31, 2020

you can start with rebase

@fvlima
Copy link
Contributor

fvlima commented Apr 26, 2020

The items 1 and 2 from the checklist were fixed here wiliamsouza#8

@fvlima
Copy link
Contributor

fvlima commented Apr 27, 2020

And about item 3, I made this comment #545 (comment) and created this PR to do it here wiliamsouza#9. This makes sense for me, but if not, just ignore it.

@auvipy auvipy self-assigned this May 8, 2020
Asif Saif Uddin added 2 commits May 9, 2020 01:30
Add project settings to be ignored in coverage
Fix flake8 and test doc issues
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, null=True,
related_name="%(app_label)s_%(class)s"
)
token = models.TextField(unique=True)

Choose a reason for hiding this comment

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

Testing locally using MySQL the migration created by this errors with MySQL err 1170, "BLOB/TEXT column 'token' used in key specification without a key length".

Reference: https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html#error_er_blob_key_without_length

Given that this is not the primary key and (if my understanding is correct) typically a value generated by the application, perhaps we could not use a database index to ensure uniqueness? Happy to make a PR if so.

Copy link
Contributor

Choose a reason for hiding this comment

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

sure plz

Choose a reason for hiding this comment

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

@fvlima
Copy link
Contributor

fvlima commented Sep 8, 2020

I think that this PR can be closed because we already have this implementation merged here #859

@auvipy auvipy closed this Sep 9, 2020
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.

None yet