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

ProviderAuthSerializer.validate_state()   A

Complexity

Conditions 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
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 auth token
11
    token = serializers.CharField(read_only=True)
12
    user = serializers.CharField(read_only=True)
13
14
    # POST OAuth/OpenID values
15
    code = serializers.CharField(write_only=True)
16
    state = serializers.CharField(required=False, write_only=True)
17
18
    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...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
19
        user = validated_data['user']
20
        return settings.SOCIAL_AUTH_TOKEN_STRATEGY.obtain(user)
21
22
    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...
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
31
        try:
32
            backend.validate_state()
33
        except exceptions.AuthException:
34
            raise serializers.ValidationError('State could not be verified.')
35
36
    def validate(self, attrs):
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 attrs 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
            user = backend.auth_complete()
47
        except exceptions.AuthException:
48
            raise serializers.ValidationError(
49
                'Failed to finish authentication.'
50
            )
51
        return {'user': user}
52