summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--awx/api/serializers.py9
-rw-r--r--awx/main/management/commands/create_oauth2_token.py8
2 files changed, 9 insertions, 8 deletions
diff --git a/awx/api/serializers.py b/awx/api/serializers.py
index f5d853525c..1972913a9d 100644
--- a/awx/api/serializers.py
+++ b/awx/api/serializers.py
@@ -1067,10 +1067,8 @@ class BaseOAuth2TokenSerializer(BaseSerializer):
).format(self.ALLOWED_SCOPES))
return value
- def create(self, validated_data, from_command_line=False):
- if not from_command_line:
- current_user = self.context['request'].user
- validated_data['user'] = current_user
+ def create(self, validated_data):
+ validated_data['user'] = self.context['request'].user
try:
return super(BaseOAuth2TokenSerializer, self).create(validated_data)
except oauth2.AccessDeniedError as e:
@@ -1088,7 +1086,6 @@ class UserAuthorizedTokenSerializer(BaseOAuth2TokenSerializer):
def create(self, validated_data):
current_user = self.context['request'].user
- validated_data['user'] = current_user
validated_data['token'] = generate_token()
validated_data['expires'] = now() + timedelta(
seconds=settings.OAUTH2_PROVIDER['ACCESS_TOKEN_EXPIRE_SECONDS']
@@ -1109,7 +1106,6 @@ class OAuth2TokenSerializer(BaseOAuth2TokenSerializer):
def create(self, validated_data):
current_user = self.context['request'].user
- validated_data['user'] = current_user
validated_data['token'] = generate_token()
validated_data['expires'] = now() + timedelta(
seconds=settings.OAUTH2_PROVIDER['ACCESS_TOKEN_EXPIRE_SECONDS']
@@ -1140,7 +1136,6 @@ class UserPersonalTokenSerializer(BaseOAuth2TokenSerializer):
read_only_fields = ('user', 'token', 'expires', 'application')
def create(self, validated_data):
- validated_data['user'] = self.context['request'].user
validated_data['token'] = generate_token()
validated_data['expires'] = now() + timedelta(
seconds=settings.OAUTH2_PROVIDER['ACCESS_TOKEN_EXPIRE_SECONDS']
diff --git a/awx/main/management/commands/create_oauth2_token.py b/awx/main/management/commands/create_oauth2_token.py
index 2d27566c12..bd4a86da2d 100644
--- a/awx/main/management/commands/create_oauth2_token.py
+++ b/awx/main/management/commands/create_oauth2_token.py
@@ -24,5 +24,11 @@ class Command(BaseCommand):
raise CommandError('The user does not exist.')
config = {'user': user, 'scope':'write'}
serializer_obj = OAuth2TokenSerializer()
- token_record = serializer_obj.create(config, True)
+
+ class FakeRequest(object):
+ def __init__(self):
+ self.user = user
+
+ serializer_obj.context['request'] = FakeRequest()
+ token_record = serializer_obj.create(config)
self.stdout.write(token_record.token)