Created
October 19, 2018 14:24
-
-
Save davestgermain/9909a67034a037f9cb32532d8079e48f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.apps import apps | |
from django.db.utils import IntegrityError | |
def create_oauth_credentials(name): | |
""" | |
Automatically create oauth credentials for applications | |
""" | |
username = 'oauth_api_%s' % name | |
try: | |
auth_user = get_user_model().objects.create_user(username) | |
except IntegrityError: | |
auth_user = get_user_model().objects.get(username=username) | |
app, created = apps.get_model('oauth2_provider.Application').objects.get_or_create( | |
name='Oauth User %s' % name, | |
user=auth_user, | |
client_type='confidential', | |
authorization_grant_type='client-credentials' | |
) | |
return app.client_id, app.client_secret, username, created |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment