Esempio n. 1
0
 def create(self, validated_data):
     instance = ApiOAuth2Application(**validated_data)
     try:
         instance.save()
     except ValidationError as e:
         detail = format_validation_error(e)
         raise exceptions.ValidationError(detail=detail)
     return instance
Esempio n. 2
0
 def create(self, validated_data):
     instance = ApiOAuth2Application(**validated_data)
     try:
         instance.save()
     except ValidationError as e:
         detail = format_validation_error(e)
         raise exceptions.ValidationError(detail=detail)
     return instance
Esempio n. 3
0
 def create(self, validated_data):
     validate_requested_scopes(validated_data)
     instance = ApiOAuth2PersonalToken(**validated_data)
     try:
         instance.save()
     except ValidationError as e:
         detail = format_validation_error(e)
         raise exceptions.ValidationError(detail=detail)
     return instance
Esempio n. 4
0
 def update(self, instance, validated_data):
     assert isinstance(instance, ApiOAuth2Application), 'instance must be an ApiOAuth2Application'
     for attr, value in validated_data.items():
         setattr(instance, attr, value)
     try:
         instance.save()
     except ValidationError as e:
         detail = format_validation_error(e)
         raise exceptions.ValidationError(detail=detail)
     return instance
Esempio n. 5
0
 def update(self, instance, validated_data):
     assert isinstance(
         instance,
         ApiOAuth2Application), 'instance must be an ApiOAuth2Application'
     for attr, value in validated_data.items():
         setattr(instance, attr, value)
     try:
         instance.save()
     except ValidationError as e:
         detail = format_validation_error(e)
         raise exceptions.ValidationError(detail=detail)
     return instance
Esempio n. 6
0
 def create(self, validated_data):
     scopes = validate_requested_scopes(validated_data.pop('scopes', None))
     if not scopes:
         raise exceptions.ValidationError(
             'Cannot create a token without scopes.')
     instance = ApiOAuth2PersonalToken(**validated_data)
     try:
         instance.save()
     except ValidationError as e:
         detail = format_validation_error(e)
         raise exceptions.ValidationError(detail=detail)
     for scope in scopes:
         instance.scopes.add(scope)
     return instance
 def update(self, instance, validated_data):
     assert isinstance(
         instance,
         ApiOAuth2Application), 'instance must be an ApiOAuth2Application'
     client_secret = validated_data.pop('client_secret', None)
     if client_secret == '':
         instance.reset_secret(save=True)
     for attr, value in validated_data.items():
         setattr(instance, attr, value)
     try:
         instance.save()
     except ValidationError as e:
         detail = format_validation_error(e)
         raise exceptions.ValidationError(detail=detail)
     return instance
Esempio n. 8
0
    def update(self, instance, validated_data):
        validate_requested_scopes(validated_data)
        assert isinstance(instance, ApiOAuth2PersonalToken), 'instance must be an ApiOAuth2PersonalToken'

        instance.deactivate(save=False)  # This will cause CAS to revoke the existing token but still allow it to be used in the future, new scopes will be updated properly at that time.
        instance.reload()

        for attr, value in validated_data.items():
            if attr == 'token_id':  # Do not allow user to update token_id
                continue
            else:
                setattr(instance, attr, value)
        try:
            instance.save()
        except ValidationError as e:
            detail = format_validation_error(e)
            raise exceptions.ValidationError(detail=detail)
        return instance