jazzband / django-oauth-toolkit

OAuth2 goodies for the Djangonauts!
https://django-oauth-toolkit.readthedocs.io
Other
3.13k stars 792 forks source link

I need client(application) object in BaseTokenView #1358

Open alikafy opened 11 months ago

alikafy commented 11 months ago

Is your feature request related to a problem?

We've added an 'IP' field into the application model, and our objective is to verify if the client's IP matches the one stored in the application model. To facilitate this, we've inherited from the 'BaseTokenView.' However, we're encountering an issue because we don't have direct access to the application object. The 'client_id' and 'client_secret' are encoded, complicating matters.

We're aware of the 'OAuth2Validator._authenticate_basic_auth' method, which sets the 'request.client' (application object), but we need to access the application object within our view.

To resolve this, we require a new structure that allows us to obtain the client object within the Token API view.

Describe the solution you'd like Add a method to BaseTokenView that gives us the app object before creating the token.

### Tasks
dopry commented 11 months ago

Just to be clear are you talking about oauth2_provider.views.base.TokenView?

dopry commented 11 months ago

Did you try something like

application = get_application_model().objects.get(client_id=client_id)