| Total Complexity | 4 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | from rest_framework import serializers |
||
| 7 | class ProviderAuthSerializer(serializers.Serializer): |
||
| 8 | id = serializers.IntegerField(read_only=True) |
||
| 9 | email = serializers.CharField(read_only=True) |
||
| 10 | code = serializers.CharField(write_only=True) |
||
| 11 | state = serializers.CharField(required=False, write_only=True) |
||
| 12 | |||
| 13 | def create(self, validated_data): |
||
| 14 | strategy = load_strategy(self.context['request']) |
||
| 15 | redirect_uri = strategy.session_get('redirect_uri') |
||
| 16 | |||
| 17 | backend_name = self.context['view'].kwargs['provider'] |
||
| 18 | backend = load_backend( |
||
| 19 | strategy, backend_name, redirect_uri=redirect_uri |
||
| 20 | ) |
||
| 21 | return backend.auth_complete() |
||
| 22 | |||
| 23 | def update(self, instance, validated_data): |
||
| 24 | pass |
||
| 25 | |||
| 26 | def validate_state(self, value): |
||
| 27 | strategy = load_strategy(self.context['request']) |
||
| 28 | redirect_uri = strategy.session_get('redirect_uri') |
||
| 29 | |||
| 30 | backend_name = self.context['view'].kwargs['provider'] |
||
| 31 | backend = load_backend( |
||
| 32 | strategy, backend_name, redirect_uri=redirect_uri |
||
| 33 | ) |
||
| 34 | |||
| 35 | try: |
||
| 36 | backend.validate_state() |
||
| 37 | except exceptions.AuthException: |
||
| 38 | raise serializers.ValidationError('State could not be verified.') |
||
| 39 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.