Debian Codegraph @

testproj/users/migrations/0002_setup_oauth2_apps.py

raw
1 # Generated by Django 2.1.3 on 2018-12-19 07:57
2 from django.conf import settings
3 from django.db import migrations
4
5
6 def add_oauth_apps(apps, schema_editor):
7 # We can't import the Person model directly as it may be a newer
8 # version than this migration expects. We use the historical version.
9 User = apps.get_model(settings.AUTH_USER_MODEL)
10 Application = apps.get_model('oauth2_provider', 'application')
11
12 user = User.objects.get(username='admin')
13
14 oauth2_apps = [
15 {
16 "user": user,
17 "client_type": "public",
18 "authorization_grant_type": "password",
19 "client_id": settings.OAUTH2_CLIENT_ID,
20 "client_secret": settings.OAUTH2_CLIENT_SECRET,
21 "redirect_uris": settings.OAUTH2_REDIRECT_URL,
22 "name": settings.OAUTH2_APP_NAME
23 }
24 ]
25
26 for app in oauth2_apps:
27 Application.objects.get_or_create(client_id=app['client_id'], defaults=app)
28
29
30 class Migration(migrations.Migration):
31 dependencies = [
32 migrations.swappable_dependency(settings.AUTH_USER_MODEL),
33 ('oauth2_provider', '0002_auto_20190406_1805'),
34 ('users', '0001_create_admin_user'),
35 ]
36
37 operations = [
38 migrations.RunPython(add_oauth_apps)
39 ]