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

Oauth2 to OIDC #2448

Closed
wants to merge 8 commits into from
Closed

Oauth2 to OIDC #2448

wants to merge 8 commits into from

Conversation

FluidSense
Copy link
Contributor

@FluidSense FluidSense commented Mar 8, 2020

What kind of a pull request is this?

Our OIDC-provider also provides Oauth2-authentication.
This ports the shop over to the oidc-provider so we avoid duplicate authentication modules.

  • QA / Code Review

Code Checklist

  • The code follows dotkom code style
  • The code passes the defined tests
  • I have added tests for the code I added
  • I have provided documentation for the code I added
  • The code is ready to be merged

(Possible) Breaking Changes

This breaks all SSO-Clients which uses Oauth2, the endpoint will have to be updated and new keys generated.

  • I have updated the build configuration
  • These changes requires changes to configuration in production
    • I have applied the required changes in production
    • I cannot apply the required changes in production before this is deployed.

Description of changes

Screenshot(s) if appropriate

Comment on lines 46 to 54
info_nibble = (
_("Nibble"),
_(
"Informasjon om dine kjøp og saldo på Nibble",
),
)

def scope_nibble(self):
return {'test':'this data was returned'}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am highly uncertain whether this is necessary or not, and if it is: what it really does..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Learned recently that an empty dictionary should be the default value. Else, "test" is added as a claim to /userinfo with the returned value.

@FluidSense FluidSense requested review from oleast and sklirg March 8, 2020 16:02
@FluidSense FluidSense force-pushed the fix/oauth2-to-oidc branch from 4d22d32 to f23bdf7 Compare March 8, 2020 17:44
@FluidSense FluidSense changed the title WIP: Oauth2 to OIDC Oauth2 to OIDC Mar 8, 2020
apps/online_oidc_provider/claims.py Outdated Show resolved Hide resolved
@@ -20,3 +23,56 @@ def authenticate(self, request):
raise exceptions.AuthenticationFailed("The oauth2 token has expired")

return oauth2_token.user, None


class TokenHasScope(BasePermission):
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we are writing our own version of TokenHasScope, instead of just using DRF's built in one? If so that should be clearly stated in a comment here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK DRF does not have a built-in TokenHasScope. We previously used oauth2_provider's TokenHasScope, made by Django OAuth Toolkit to provide a support layer for DRF. As we are no longer using oauth2_provider, we cannot use their TokenHasScope either.

Copy link
Member

Choose a reason for hiding this comment

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

I'm also a bit vary of this. Could you do some more research with regards to this? Could we depend on oauth2_provider for that function alone, or is it tightly coupled to its own OAuth2 provider? Do we want to depend on it, or do we want to run our own fork of the code? At least get some tests up if we do :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I've been digging through the code for the OAuth2 provider, and the answer is a big I don't know. I guess I can continue testing some more, but it seems that if we are to use the TokenHasScope from oauth2_provider, we will need duplicates of settings, to ensure that the oidc_provider and oauth2_provider has the same settings, as TokenHasScope relies on settings for oauth2_provider.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The class is by the way taken from this stale issue at oidc_provider's repo juanifioren/django-oidc-provider#342

Other issues related to this worth a read:
juanifioren/django-oidc-provider#242
juanifioren/django-oidc-provider#78

@@ -7,10 +7,7 @@

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's that smart to change migrations.

Removing the dependency on this migration doesn't remove the tables/columns from the database. A separate migration is required to do this. After that migration is done, a new change can be done where the requirement is removed, and migrations can be squashed to remove the dependency.

Copy link
Member

Choose a reason for hiding this comment

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

I just saw that you've done it correctly with the sso app migration, good. But I still think this migration shouldn't be changed (and therefore all the sso migrations have to be kept), until it is squashed so that sso is fully removed. It's a bit of a long run, but I don't think it matters that much to keep the migrations in for a while. Maybe @duvholt could chime in on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sklirg I see! So it would be better to not involve this and perhaps add something like it in it's own PR for example?

@oleast oleast mentioned this pull request Mar 29, 2020
6 tasks
Copy link
Member

@oleast oleast left a comment

Choose a reason for hiding this comment

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

Looks very good aside from the points that sklirg has pointed out!

Also just a small heads up for that I added a few Nibble tests which still use the old Oauth2TestCase, because the API-was still using that at the time. It should be OK to just replace a few lines, but the change needs to be made

@FluidSense
Copy link
Contributor Author

I am a bit conflicted about this seeing as https://github.com/juanifioren/django-oidc-provider is relatively stale and not well-documented. On the other hand, we are already using it and this would require less manual work (i.e. issuing new tokens and secrets to all current applications) while satisfying our current needs.

@oleast
Copy link
Member

oleast commented Apr 18, 2020

I am a bit conflicted about this seeing as juanifioren/django-oidc-provider is relatively stale and not well-documented. On the other hand, we are already using it and this would require less manual work (i.e. issuing new tokens and secrets to all current applications) while satisfying our current needs.

I can agree in being a bit conflicted on it, but as of right now it still works. If we end up needing to change we could export to a completly separate OpenID provider without too much hassle I think? We may need everyone to change their passwords at worst?

@Aborysa had a look into setting up KeyCloak earlier, which might still be an alternative. Is it much work to get working as a bare-minimum?

Base automatically changed from develop to main January 31, 2021 16:52
@FluidSense FluidSense closed this Jul 25, 2021
@FluidSense FluidSense deleted the fix/oauth2-to-oidc branch July 25, 2021 14:41
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.

4 participants