idlesign/django-oauthost

View on GitHub

Showing 27 of 27 total issues

File endpoints.py has 681 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
from base64 import b64decode
from datetime import datetime
from time import time
from typing import List, Union
Severity: Major
Found in oauthost/endpoints.py - About 1 day to fix

    Function register_client has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def register_client(
            title: str,
            identifier: str,
            redirect_uri: str,
            registrant: 'User',
    Severity: Minor
    Found in oauthost/toolbox.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function handle has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle(self, *args, **options):
    
            if not len(args):
                raise CommandError('This command accepts space delimited list of application names.')
    
    
    Severity: Minor
    Found in oauthost/management/commands/syncscopes.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    File models.py has 283 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    from uuid import uuid4
    from random import randrange
    
    from django.conf import settings
    from django.db import models, IntegrityError
    Severity: Minor
    Found in oauthost/models.py - About 2 hrs to fix

      Function get_client has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_client(self) -> Client:
              """Returns client object."""
              client = None
              auth_error_headers = {}
              client_id = None
      Severity: Minor
      Found in oauthost/endpoints.py - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function filter_scopes has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def filter_scopes(self, client: Client) -> List[Scope]:
              """Gets space delimited list of scopes from client request,
              and returns a list of scope objects, corrected according
              to auth server settings.
      
      
      Severity: Minor
      Found in oauthost/endpoints.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function register_client has 9 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def register_client(
      Severity: Major
      Found in oauthost/toolbox.py - About 1 hr to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                migrations.AddField(
                    model_name='authorizationcode',
                    name='user',
                    field=models.ForeignKey(verbose_name='User', to=settings.AUTH_USER_MODEL, help_text='The user authorization is granted for.', on_delete=models.CASCADE),
        Severity: Major
        Found in oauthost/migrations/0001_initial.py and 1 other location - About 1 hr to fix
        oauthost/migrations/0001_initial.py on lines 104..107

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 39.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                migrations.AddField(
                    model_name='client',
                    name='user',
                    field=models.ForeignKey(verbose_name='Registrant', to=settings.AUTH_USER_MODEL, help_text='User who registered this client.', on_delete=models.CASCADE),
        Severity: Major
        Found in oauthost/migrations/0001_initial.py and 1 other location - About 1 hr to fix
        oauthost/migrations/0001_initial.py on lines 122..125

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 39.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                migrations.AddField(
                    model_name='client',
                    name='scopes',
                    field=models.ManyToManyField(help_text='The scopes client is restricted to. <i>All registered scopes will be available for the client if none selected.</i>', to='oauthost.Scope', null=True, verbose_name='Scopes', blank=True),
        Severity: Major
        Found in oauthost/migrations/0001_initial.py and 1 other location - About 1 hr to fix
        oauthost/migrations/0001_initial.py on lines 116..119

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 38.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                migrations.AddField(
                    model_name='authorizationcode',
                    name='scopes',
                    field=models.ManyToManyField(help_text='The scopes token issued with this code should be restricted to.', to='oauthost.Scope', null=True, verbose_name='Scopes', blank=True),
        Severity: Major
        Found in oauthost/migrations/0001_initial.py and 1 other location - About 1 hr to fix
        oauthost/migrations/0001_initial.py on lines 98..101

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 38.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                migrations.AlterField(
                    model_name='token',
                    name='access_token',
                    field=models.CharField(verbose_name='Access Token', blank=True, max_length=32, help_text='Token to be used to access resources.', unique=True),
        Severity: Minor
        Found in oauthost/migrations/0002_auto_20150927_1933.py and 1 other location - About 45 mins to fix
        oauthost/migrations/0002_auto_20150927_1933.py on lines 14..17

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 35.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Function get_response_document has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def get_response_document(
        Severity: Minor
        Found in oauthost/endpoints.py - About 45 mins to fix

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                  migrations.AlterField(
                      model_name='authorizationcode',
                      name='code',
                      field=models.CharField(verbose_name='Code', blank=True, max_length=7, help_text='Code issued upon authorization.', unique=True),
          Severity: Minor
          Found in oauthost/migrations/0002_auto_20150927_1933.py and 1 other location - About 45 mins to fix
          oauthost/migrations/0002_auto_20150927_1933.py on lines 29..32

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 35.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Avoid deeply nested control flow statements.
          Open

                              if register_unknown_scopes:
                                  scope_obj = Scope(identifier=scope, title=scope)
                                  scope_obj.save()
          
                              else:
          Severity: Major
          Found in oauthost/toolbox.py - About 45 mins to fix

            Function save has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def save(self, force_insert=False, force_update=False, **kwargs):
                    if not self.code:
                        while True:
                            self.code = self.generate_code()
                            try:
            Severity: Minor
            Found in oauthost/models.py - About 45 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function save has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def save(self, force_insert=False, force_update=False, **kwargs):
                    if not self.access_token:
                        while True:
                            self.access_token = self.generate_token()
                            self.refresh_token = self.generate_token()
            Severity: Minor
            Found in oauthost/models.py - About 45 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function validate_token has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def validate_token(self) -> bool:
            
                    if self._token is None:
                        return False
            
            
            Severity: Minor
            Found in oauthost/auth_handlers.py - About 45 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function save has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def save(self, force_insert=False, force_update=False, **kwargs):
            
                    if not self.identifier:
            
                        while True:
            Severity: Minor
            Found in oauthost/models.py - About 45 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def __init__(
            Severity: Minor
            Found in oauthost/endpoints.py - About 35 mins to fix
              Severity
              Category
              Status
              Source
              Language