Passed
Pull Request — master (#244)
by Piotr
01:09
created

ProviderAuthSerializer.validate_state()   A

Complexity

Conditions 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
1
from rest_framework import serializers
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
introduced by
Unable to import 'rest_framework'
Loading history...
2
3
from social_core import exceptions
0 ignored issues
show
introduced by
Unable to import 'social_core'
Loading history...
4
from social_django.utils import load_backend, load_strategy
0 ignored issues
show
introduced by
Unable to import 'social_django.utils'
Loading history...
5
6
from djoser.conf import settings
7
8
9
class ProviderAuthSerializer(serializers.Serializer):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
10
    # GET authorization URL
11
    id = serializers.IntegerField(read_only=True)
0 ignored issues
show
Coding Style Naming introduced by
The name id does not conform to the class attribute naming conventions (([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
12
    email = serializers.CharField(read_only=True)
13
14
    # GET auth token
15
    token = serializers.CharField(read_only=True)
16
    user = serializers.CharField(read_only=True)
17
18
    # POST OAuth/OpenID values
19
    code = serializers.CharField(write_only=True)
20
    state = serializers.CharField(required=False, write_only=True)
21
22
    def create(self, validated_data):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The argument validated_data seems to be unused.
Loading history...
23
        strategy = load_strategy(self.context['request'])
24
        redirect_uri = strategy.session_get('redirect_uri')
25
26
        backend_name = self.context['view'].kwargs['provider']
27
        backend = load_backend(
28
            strategy, backend_name, redirect_uri=redirect_uri
29
        )
30
        user = backend.auth_complete()
31
        return settings.SOCIAL_AUTH_TOKEN_STRATEGY.obtain(user)
32
33
    def update(self, instance, validated_data):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
34
        pass
35
36
    def validate_state(self, value):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The argument value seems to be unused.
Loading history...
37
        strategy = load_strategy(self.context['request'])
38
        redirect_uri = strategy.session_get('redirect_uri')
39
40
        backend_name = self.context['view'].kwargs['provider']
41
        backend = load_backend(
42
            strategy, backend_name, redirect_uri=redirect_uri
43
        )
44
45
        try:
46
            backend.validate_state()
47
        except exceptions.AuthException:
48
            raise serializers.ValidationError('State could not be verified.')
49