Django OAuth toolkit: Automatically generate a client_id and client_secret for new user?

1.4k Views Asked by At

I am using OAuth client credentials to offer my customers access to our API so they can integrate with their systems.

To register an application and generate a client_id and client_secret the Django-oauth-toolkit documentation says the form o/applications/register/ must be completed (documentation here). Is it possible to automatically issue a client_id and client_secret to my user when they sign up instead of directing them to this form ?

1

There are 1 best solutions below

0
On

Here's an example to get the data that you need. All you need to do is to integrate this into your custom user model.

from oauth2_provider.models import get_application_model
Application = get_application_model()
app = Application()
app.name = 'test'
app.client_type = 'confidential'
app.authorization_grant_type = 'password'
app.user_id = 1
app.save()

#client_id:
app.client_id

#client_secret:
app.client_secret