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
Allow User creation after token validation. #534
Comments
Hi @cristobalmackenzie Good to hear! What you can do is create an import string that allows users to specify how to get the user. An example is the authentication rule callable. Then, in get_user itself, you can check the api settings to see if a callable was set. If it was, pass the data (from the validation) to the callable and return the result. If a callable was not set, you can run the code that is currently there. If that's confusing, create a PR of what you think we should we and we can discuss further :) |
Hi @Andrew-Chen-Wang , this is clear and sounds like a good solution to me. I'll work on it and check-in with any updates. |
Hi @cristobalmackenzie I'm running into this as I want to use auth0, and was curious how you went about solving this in the end. Cheers. |
I solved this by overriding Some gotchas you might encounter:
|
@cristobalmackenzie, @dcopso . I've been trying setup AWS Cognito using My SIMPLE_JWT = {
"JWK_URL": "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_XXXXXXX/.well-known/jwks.json",
"ALGORITHM": "RS256",
"AUDIENCE": "<my cognito app client>",
"ISSUER": "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_XXXXXXX",
} myview.py from rest_framework_simplejwt.authentication import JWTAuthentication
class TesteViewSet(
mixins.ListModelMixin,
viewsets.GenericViewSet,
):
queryset = MyModel.objects.all()
serializer_class = TesteSerializer
authentication_classes = [JWTAuthentication] What more I need to do? Tks in advance, :) |
Hi ! I've successfully set up a Django project that validates JWTs from AWS Cognito using the
JWK_URL
setting.I ran into a problem though, which is the fact that users making requests to my API don't necessarily have a corresponding record in the local
User
table, soJWTAuthentication.get_user
runs into problems. I would like to have the chance to create these users.I ended up subclassing
JWTAuthentication
and made it work by overriding theget_user
method.I think this could be a good improvement to the library, and is probably a common requirement from users in positions like mine (using external auth).
With a bit of guidance as to how exactly this could/should be implemented, I'd be glad to work on a small PR.
The text was updated successfully, but these errors were encountered: